akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(c) c.begin(),c.end()

using namespace std;
typedef long long ll;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  vector<ll> Asum(N + 1);
  REP(i, N) Asum[i + 1] = Asum[i] + A[i];
  sort(ALL(Asum));
  Asum.push_back(-1);
  ll cnt = 1, ans = 0;
  REP (i, N + 1) {
    if (Asum[i] != Asum[i + 1]) {
      ans += (cnt - 1)*cnt / 2;
      cnt = 1;
    } else {
      cnt++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6400
#D
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[0]*Q
C=[0]*Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())
    
d=dict(Counter(A))
#print(d)
summ=sum(A)

for i in range(Q):
    if C[i] not in d:
        d[C[i]]=0
    if B[i] in d:
        summ -= d[B[i]]*B[i]
        summ += d[B[i]]*C[i]
        d[C[i]] += d[B[i]]
        d[B[i]]=0
    print(summ)
        
#print(d)

Measured memory_bytes: 27608
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split())) + [0]

carry = 0
ans = 0
for i in range(N+1):
    if A[i] <= carry:
        ans += A[i]
        carry = B[i]
    else:
        A[i] -= carry
        ans += carry
        if A[i] >= B[i]:
            ans += B[i]
            carry = 0
        else:
            ans += A[i]
            carry = B[i] - A[i]

print(ans)


Measured memory_bytes: 18476
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   ll n; cin >> n;
   ll sum = 0;
   rep(i, n){
      if((i+1)%3==0 || (i+1)%5==0){
         continue;
      }

      sum += i+1;
   }
   cout << sum << endl;
   return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ll n, i, j, w;
	cin >> n >> w;
	vll a(n), b(n), dp(w + 1, 0);
	for(i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	for(i = 0; i < n; i++)
		for(j = w - a[i]; j >= 0; j--)
			dp[a[i] + j] = max(dp[j] + b[i], dp[a[i] + j]);
	for(i = 1; i <= w; i++)
		dp[i] = max(dp[i - 1], dp[i]);
	cout << dp[w] << endl;	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S; 
	reverse(S.begin(), S.end()); 
	S += '0'; 
	int dp[1000010][2] = {}; // j=0はぴったり、j=1は何らかの10^kを借りてる
	dp[0][1] = 1145141919; 
	for(int i = 1; i <= S.size(); i++){
		int now = S.at(i-1) - '0'; 
		dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + now;
		dp[i][1] = min(dp[i-1][0] + 11 - now, dp[i-1][1] + 9 - now); 
	}
	cout << dp[S.size()][0] << endl; 
}

Measured memory_bytes: 9220
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		if (N % 1000 == 0) {
			System.out.println(0);
		} else {
			int cnt = N / 1000 + 1;
			System.out.println((1000 * cnt) - N);
		}
	}
}


Measured memory_bytes: 35836
N = int(input())

A = list(map(int,input().split()))
A = sorted(A)
ans = 0
for i in range(N):
    if i == 0:
        ans += (A[i]+A[i+1])/2
    elif i<N-1:
        ans = (ans+A[i+1])/2
print(ans)


Measured memory_bytes: 2940
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define MAX 2100000000
#define PI 3.14159265358979323846
const int Mod = 100000007;

using namespace std;

int main(void)
{
	string n;
	int a, b, c, d;
	int num;
	char op1, op2, op3;
	cin >> n;

	a = n[0] - '0';
	b = n[1] - '0';
	c = n[2] - '0';
	d = n[3] - '0';


	for (int i = 0; i < 2; i++)
	{
		if (i == 0)
		{
			op1 = '+';
		}
		else
		{
			op1 = '-';
		}
		for (int j = 0; j < 2; j++)
		{
			if (j == 0)
			{
				op2 = '+';
			}
			else
			{
				op2 = '-';
			}
			for (int k = 0; k < 2; k++)
			{
				if (k == 0)
				{
					op3 = '+';
				}
				else
				{
					op3 = '-';
				}
				if (op1 == '+')
				{
					if (op2 == '+')
					{
						if (op3 == '+')
						{
							num = a + b + c + d;
						}
						else
						{
							num = a + b + c - d;
						}
					}
					else
					{
						if (op3 == '+')
						{
							num = a + b - c + d;
						}
						else
						{
							num = a + b - c - d;
						}
					}
				}
				else
				{
					if (op2 == '+')
					{
						if (op3 == '+')
						{
							num = a - b + c + d;
						}
						else
						{
							num = a - b + c - d;
						}
					}
					else
					{
						if (op3 == '+')
						{
							num = a - b - c + d;
						}
						else
						{
							num = a - b - c - d;
						}
					}
				}

				if (num == 7)
				{
					cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())

x=n//k
#print(x)
if k%2==0:
    y=(n+k//2)//k
else:
    y=0
if x>=2:
    x=x+x*(x-1)*(x-2)+x*(x-1)*3
elif x==1:
    x=x+x*(x-1)*3
if y>=2:
    y=y+y*(y-1)*(y-2)+y*(y-1)*3
elif y==1:
    y=y+y*(y-1)*3
print(x+y)


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c;
    while(true){
        if(a > b){
             d=a;
             a=b;
             b=d;
        }else if(b>c){
             d=b;
             b=c;
             c=d;
        }else if(a>b){
             d=a;
             a=b;
             b=d;
        }else{
        break;
        }
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}

Measured memory_bytes: 3092
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	ST := sc.nexts()
	S := ST[0]
	T := ST[1]
	fmt.Println(T + S)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


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

using ll=long long;



void solve(){
    string s;
    int cnt=0;
    cin>>s;
    for(int i=0; i<3; i++){
        if(s[i]=='1')cnt++;
    }
    cout<<cnt<<endl;   
}

signed main(){
    //while(1)
    solve();
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;

    string T = "";
    ll d = 0;
    REP(i, N) {
        if (S[i] == '(')
            d++;
        else
            d--;

        if (d < 0) {
            T.push_back('(');
            d++;
        }
    }

    cout << T << S;
    while (d > 0) {
        d--;
        cout << ')';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input().rstrip()

ns = [None] * n
ns[0] = 0
nn = 0
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        nn += 1
    ns[i + 1] = nn
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1

    print(ns[r] - ns[l])

Measured memory_bytes: 6188
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
void solve()
{
  int ans=0,pfs=0,n;
  cin>>n;
  int ar[n];
  frr(i,n)cin>>ar[i];
  for(int i=n-1;~i;i--)
  {
  	ans=(ans+ar[i]*pfs)%MOD;
  	pfs=(pfs+ar[i])%MOD;
  }
  cout<<ans<<endl;

}
signed main()
{
  fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}
//APPROACHING A QUESTION
//+ Think of binary search (max of min etc also if n<=2*10^5)
//+ Think of common dp states (Even if it appears as maths but constraints are small)
//+ Check constraints
//+ Keep calm and enjoy the question
//+ Be sure to remove MOD from binpow (if needed)
//+ Try bidirectional analysis for constructive questions
//+ If given some sequence try thinking of prefix sums
//+ If constraints are too large maybe its simple maths
//+ In questions with binary operations think of bits independently and also the change pattern
//+ If two or more binary operations are given mostly there is a relation between them and an arithmatic operator

Measured memory_bytes: 5200
#include<iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){    
  int N,b;
    int sum=0;
    cin >> N;
    int A[N],B[N],C[N-1];

    for(int i=0;i<N;i++){
      cin >> A[i];
    } 
    for(int i=0;i<N;i++){
      cin >> b;
      sum += b;
    }
    for(int i=0;i<N-1;i++){
      cin >> C[i];
    }

    for(int i=0;i<N-1;i++){
      if(A[i]+1 == A[i+1]){
	sum += C[A[i]-1];
      }
    }
    
    cout << sum << endl;
}


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

int main() {
	ll ans,n;
	cin>>n;
	if(n%1000!=0) {
	    ll res=n/1000;
	    ans=(res+1)*1000-n;
	}
	else {
	    ans =0;
	}
	cout<<ans<<endl;
	return 0;
}


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

int64_t	calc_partial_sum(int n, int k, const vector<int> &a_vec)
{
	int64_t	s = 0;
	int64_t	max_s = 0;
	for (int i = 0; i < k; ++i)
		s += a_vec.at(i);
	max_s = s;
	for (int i = k; i < n; ++i) {
		s += a_vec.at(i) - a_vec.at(i - k);
		if (max_s < s)
			max_s = s;
	}
	return max_s;
}

int	main()
{
	int	n, k;
	while (cin >> n >> k) {
		if (n == 0 && k == 0)
			break;
		vector<int>	a_vec(n);
		for (int i = 0; i < n; ++i)
			cin >> a_vec.at(i);
		cout << calc_partial_sum(n, k, a_vec) << endl;
	}
}



Measured memory_bytes: 3020
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int MAXN = 2e5 + 5, MAXM = 2e5 + 5, N = 2e5 + 5;
const int MAXQ = 100010;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
        to[++tot] = v;
        nxt[tot] = Head[u];
        Head[u] = tot;
}*/
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
int num[100005];
int main()
{
        int n;
        int k;
        int minn = INT_MAX;
        int aim;
        read(n), read(k);
        for (int i = 1; i <= n; i++)
        {
                read(num[i]);
                if (num[i] < minn)
                {
                        minn = num[i];
                        aim = i;
                }
        }
        int ans = 0;
        if (aim == 1)
        {
                if ((n - 1) % (k - 1))
                {
                        ans++;
                }
                ans += (n - 1) / (k - 1);
                cout << ans << endl;
                return 0;
        }
        if (aim == n)
        {
                if ((aim - 1) % (k - 1))
                {
                        ans++;
                }
                ans += (aim - 1) / (k - 1);
                cout << ans << endl;
                return 0;
        }
        if (aim <= k)
        {
                ans++;
                aim = k;
                if ((n - aim) % (k - 1))
                {
                        ans++;
                }
                ans += (n - aim) / (k - 1);
                cout << ans << endl;
                return 0;
        }
        if (aim > n - k)
        {
                ans++;
                aim = n - k + 1;
                if ((aim - 1) % (k - 1))
                {
                        ans++;
                }
                ans += (aim - 1) / (k - 1);
                cout << ans << endl;
                return 0;
        }
        ans = INT_MAX;
        int anser = 0;
        for (int laim = max(1, aim - k + 1); laim <= aim; laim++)
        {
                int raim = laim + k - 1;
                anser = 1;
                if ((laim - 1) % (k - 1))
                {
                        anser++;
                }
                anser += (laim - 1) / (k - 1);
                if ((n - raim) % (k - 1))
                {
                        anser++;
                }
                anser += (n - raim) / (k - 1);
                ans = min(ans, anser);
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))

flag = False
for i in range(n):
    if a[i] < 0:
        if flag == False:
            flag = True
        else :
            flag = False
        a[i] = -1 * a[i]

list.sort(a, reverse=True)        
sum_a = 0

for i in range(n):
    if i == n - 1 and flag:
        sum_a -= a[i]
    else :
        sum_a += a[i]
print(sum_a)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N * (N - 1) / 2), B(N * (N - 1) / 2), C(N * (N - 1) / 2),
      D(N * (N - 1) / 2);
  for (int i = 0; i < N * (N - 1) / 2; ++i)
    cin >> A[i] >> B[i] >> C[i] >> D[i];
  vector<int> s(N + 1);
  for (int i = 0; i < N * (N - 1) / 2; ++i)
    if (C[i] > D[i])
      s[A[i]] += 3;
    else if (C[i] == D[i])
      ++s[A[i]], ++s[B[i]];
    else
      s[B[i]] += 3;
  for (int i = 1; i <= N; ++i) {
    int r = 1;
    for (int j = 1; j <= N; ++j)
      if (s[i] < s[j])
        ++r;
    cout << r << endl;
  }
}


Measured memory_bytes: 3184
L = input()

n = 1
a = 0

for i in L:

    on = n
    oa = a

    if i == "0":
        n = on
        a = 3 * oa

    else:
        n = on * 2
        a = 3 * oa + on

    a %= 10 ** 9 + 7
    n %= 10 ** 9 + 7

print ((a+n) % (10 ** 9 + 7))
        

Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n;
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<string> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
      cin>>n;
      for(long long int i=0;i<n;i++)
      {
         cin>>s;
         st.insert(s);
      }
      cout<<st.size();
   return 0;
}


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

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int count = 0;
    int ans = 0;
    for(int i=0; i<n; i++){
        if(i <= k-1) ans += x;
        else ans += y;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
  int src, dst;
  CostType cost;
  Edge(int src_, int dst_, CostType cost_ = 0) : src(src_), dst(dst_), cost(cost_) {}
  inline bool operator<(const Edge &rhs) const {
    return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
  }
  inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
  inline bool operator>(const Edge &rhs) const {
    return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
  }
  inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};

struct DoubleSweep {
  using Pci = pair<CostType, int>;

  int s, t;
  CostType diameter;

  DoubleSweep(const vector<vector<Edge> > &graph_) : graph(graph_) {
    Pci tmp1 = dfs(-1, 0);
    s = tmp1.second;
    Pci tmp2 = dfs(-1, tmp1.second);
    t = tmp2.second;
    diameter = tmp2.first;
  }

private:
  vector<vector<Edge> > graph;

  Pci dfs(int par, int ver) {
    Pci res = {0, ver};
    for (Edge e : graph[ver]) if (e.dst != par) {
      Pci result = dfs(ver, e.dst);
      result.first += e.cost;
      if (result.first > res.first) res = result;
    }
    return res;
  }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<vector<Edge> > graph(n);
  REP(i, n - 1) {
    int a, b; cin >> a >> b; --a; --b;
    graph[a].emplace_back(Edge(a, b, 1));
    graph[b].emplace_back(Edge(b, a, 1));
  }
  DoubleSweep ds(graph);
  cout << ((ds.diameter + 1) % 3 == 2 ? "Second\n" : "First\n");
  return 0;
}


Measured memory_bytes: 37120
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

class Info:
    def __init__(self,arg_start,arg_end,arg_S):
        self.start = arg_start
        self.end = arg_end
        self.S = arg_S


LOC = []
POOL = []

line = input()
loc = 0
sum_S = 0

for ch in line:

    if ch == '\\':

        LOC.append(loc)

    elif ch == '/':

        if len(LOC) == 0:
            continue

        tmp_start = int(LOC.pop())
        tmp_end = loc
        tmp_S = tmp_end-tmp_start;
        sum_S += tmp_S;

        #既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
        while len(POOL) > 0:
            if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
                tmp_S += POOL[-1].S
                POOL.pop()
            else:
                break

        POOL.append(Info(tmp_start,tmp_end,tmp_S))

    else:
        pass

    loc += 1

print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")

while len(POOL) > 0:
    print(" %d"%(POOL[0].S),end = "") #先頭から
    POOL.pop(0)

print()



Measured memory_bytes: 7360
s = input()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)    
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
else:
    print(1)  

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long n;
	cin >> n;
	n *= 4;

	b = min(b, 2 * a);
	c = min(c, 2 * b);
	d = min(d, 2 * c);

	long long res = 0;
	if (n % 2 == 1) {
		res += a;
		--n;
	}

	n /= 2;
	if (n % 2 == 1) {
		res += b;
		--n;
	}

	n /= 2;
	if (n % 2 == 1) {
		res += c;
		--n;
	}

	n /= 2;
	res += n * d;

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
/*
 * atcoder/abc117_3rd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * f(x) = (x xor a_1) + (x xor a_2) + ... + (x xor a_N) の最大値
 *
 * a_nのすべてについて桁ごとに0と1の数を数える.
 * 0が多ければ反転したいのでxのn桁目は1. 1が多ければそのままにしたいのでn桁目は0. ... (1)
 *
 * x <= Kなので、上位桁から見ていって、以下のように場合分けをする.
 * a) n桁目以前にx <= Kが確定している場合
 *   a.i) Kのn桁目の値に関わらず(1)のロジックで決定. max(0の個数, 1の個数) * (1<<n)
 * b) x <= Kが未確定の場合
 *   b.i) Kのn桁目が0の場合: xのn桁目も0. 1の個数 * (1<<n)
 *   b.ii)          1で、かつxを0にする場合: 1の個数 * (1<<n) でかつn+1桁目以後 x <= Kが確定
 *   b.iii)                  xを1にする場合: 0の個数 * (1<<n) でかつ未確定
 */
ll N, K;
vector<ll> A;
ll dp[45][2];
int nth(ll bits, int n) {
  return (bits>>n)&1;
}

ll rec(int n=39, bool l = false) {
  if (n == -1) return 0;
  ll &cc = dp[n][l];
  if (~cc) return cc;
  int num1 = 0;
  for (auto&& a: A) num1 += nth(a, n);
  int num0 = N-num1;
  ll D = 1LL<<n;
  ll max_ = 0;
  if (l) {
    chmax(max_, max(num1, num0) * D + rec(n-1, true));
    return cc = max_;
  }

  int nK = nth(K, n);
  if (nK == 0) {
    chmax(max_, num1 * D + rec(n-1, false));
  }
  else {
    chmax(max_, num1 * D + rec(n-1, true));
    chmax(max_, num0 * D + rec(n-1, false));
  }
  return cc = max_;
}

void solve() {
  cin >> N >> K;
  A.resize(N);
  loop(n,0,N) cin >> A[n];
  memset(dp, -1, sizeof(dp));
  cout << rec() << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define FOR(i, a, b) for(int i = (a);i <= (b); i++)
#define ROF(i, a, b) for(int i = (a);i >= (b); i--)
const int N = 1111;
int n, m, K;
int a[12][N];
int cnt[12], add[12];
int cal(int s){
    memset(cnt, 0, sizeof cnt);
    int num = 0;
    FOR(i, 0, n - 1)num += s >> i & 1;
    s |= 1 << (n - 1);
    FOR(j, 1, m){
        int tot = 0, now = 0;
        memset(add, 0, sizeof add);
        FOR(i, 1, n){
            now += a[i][j];
            if(s >> (i - 1) & 1){
                add[++tot] += now;
                if(add[tot] > K)return 1e9;
                now = 0;
            }
        }
        FOR(i, 1, tot){
            cnt[i] += add[i];
            if(cnt[i] > K){
                num++;
                memset(cnt, 0, sizeof cnt);
                j--;
                break;
            }
        }
    }
    //printf("num=%d s=%d\n", num, s);
    return num;
}
int main(){
    cin>>n>>m>>K;
    FOR(i, 1, n){
        FOR(j, 1, m)scanf("%1d", &a[i][j]);
    }
    int ans = 1e9;
    FOR(i, 0, (1 << (n - 1)) - 1){
        ans = min(ans, cal(i));
    }   
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

ac = [0]*N
wa = [0]*N
for i in range(M):
    p,s = input().split()
    p = int(p)-1
    if s == "AC":
        ac[p] = 1
    elif ac[p] == 0:
        wa[p] += 1
    
print(sum(ac),sum([[0,wa[x]][ac[x]] for x in range(N)]),sep=" ")





Measured memory_bytes: 51756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	long long N;
	scanf("%lld", &N);

	long long k = sqrt(N);

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

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		String out;

		out = a * b % 2 == 0 ? "Even" : "Odd";

		System.out.println(out);
	}
}

Measured memory_bytes: 22740
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    int cnt = 0;   
    
    for(int i=A;i<=B;i++){
      if(i%10 == (i/10000)%10 && (i/10)%10 == (i/1000)%10){
        cnt++; 
      }
    }
    System.out.println(cnt);
  }
}

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

int main(){ 
    int n;
    int b=0;
    int c=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
    cin>> a[i];
    }
    for(int i=0;i<n;i++){
        b=max(b,a[i]);
    }
    for(int i=0;i<n;i++){
        c+=a[i];
    }
    if(c-b*2>0){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


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

int main()
{

    long long int n;
    cin>>n;
    long long ans = 0 ;
    if(n%2==0)
    {
        ans = (n/2)*(n+1);
    }
    else
    {
        ans = n*((n+1)/2);
    }
    cout<<ans-n<<endl;
    return 0;
}

Measured memory_bytes: 256
N =int(input())
l=[[int(i)for i in input().split()]for j in range(N)]
l =sorted(l,key=lambda x:sum(x),reverse=True)
ans =[0,0]
nu = 0
for i in l:
    ans[nu] += i[nu]
    if nu == 0:
        nu = 1
    else:
        nu = 0
print(ans[0]-ans[1])

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


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

	LL ans = K;
	rep(i,N-1) ans *= K - 1;
	cout << ans << endl;
	
}












Measured memory_bytes: 3636
import Foundation

func main() {
    var inputString = readLine()!
    var split: [Int] = inputString.components(separatedBy: " ").map{Int(String($0))!}
    
    let n = split[0]
    let d = split[1]
    let distance = d*d
    var res = 0
    
    for _ in 1...n {
        inputString = readLine()!
        split = inputString.components(separatedBy: " ").map{Int(String($0))!}
        
        let h = split[0]
        let w = split[1]
        
        if (h*h+w*w <= distance) {
            res += 1
        }
    }
    
    print(res)
}

main()

Measured memory_bytes: 14180
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, M;
vector<int> H;
vector<int> A, B;
vector<bool> good;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  H.resize(N);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    H[i] = tmp;
  }
  A.resize(M);
  B.resize(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A[i] = a;
    B[i] = b;
  }

  good.resize(N, true);
  for (int i = 0; i < M; i++) {
    if (H[A[i]] == H[B[i]]) {
      good[A[i]] = false;
      good[B[i]] = false;
    } else if (H[A[i]] < H[B[i]]) {
      good[A[i]] = false;
    } else if (H[A[i]] > H[B[i]]) {
      good[B[i]] = false;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (good[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3884
n,k = map(int, input().split())

ok = [ [0]*k for _ in range(k) ]
ng = [ [0]*k for _ in range(k) ]

ok_cnt = 0
ng_cnt = 0
for _ in range(n):
    x,y,c = map(str, input().split())
    x = int(x)%(k*2)
    y = int(y)%(k*2)
    if (x < k and y < k and c=='W') or (x >= k and y >= k and c=='W') or (x < k and y>= k and c =='B') or (x >= k and y < k and c =='B'):
        ok[x%k][y%k] += 1
        ok_cnt += 1
    else:
        ng[x%k][y%k] += 1
        ng_cnt += 1

ok_csums = [ [0]*(k+1) for _ in range(k+1)]
for i in range(k):
    for j in range(k):
        ok_csums[i+1][j+1] = ok_csums[i+1][j] + ok_csums[i][j+1] - ok_csums[i][j] + ok[i][j]

ng_csums = [ [0]*(k+1) for _ in range(k+1)]
for i in range(k):
    for j in range(k):
        ng_csums[i+1][j+1] = ng_csums[i+1][j] + ng_csums[i][j+1] - ng_csums[i][j] + ng[i][j]

    
ans = max(ok_cnt, ng_cnt)

# l u r b
for i in range(0,k+1):
    for j in range(0,k+1):
        ok_sum = ok_csums[i][j]
        ok_sum += (ok_csums[k][k] - ok_csums[i][k]- ok_csums[k][j] + ok_csums[i][j])
        ng_sum = ng_csums[i][k] - ng_csums[i][j]
        ng_sum += (ng_csums[k][j] - ng_csums[i][j])

        # ng_sum = 2*ng_cnt - ng_sum
        ans = max(ok_sum+ng_sum, ans)

for i in range(0,k+1):
    for j in range(0,k+1):
        ok_sum = ok_csums[i][k] - ok_csums[i][j]
        ok_sum += (ok_csums[k][j] - ok_csums[i][j])
        ng_sum = ng_csums[i][j]
        ng_sum += (ng_csums[k][k] - ng_csums[i][k]- ng_csums[k][j] + ng_csums[i][j])
        # ng_sum -= 2*ng_cnt
        # ng_sum = 2*ng_cnt - ng_sum
        ans = max(ok_sum+ng_sum, ans)


# # l u
# for i in range(1,k+1):
#     for j in range(1,k+1):
#         ok_sum = ok_csums[i][j]
#         ng_sum = ng_cnt - ng_csums[i][j]
#         ans = max(ok_sum+ng_sum, ans)

# # r b
# for i in range(0,k):
#     for j in range(0,k):
#         ok_sum = ok_csums[k][k] - ok_csums[i][k]-ok_csums[k][j] + ok_csums[i][j]
#         ng_sum = ng_cnt - (ng_csums[k][k] - ng_csums[i][k]-ng_csums[k][j] + ng_csums[i][j])
#         ans = max(ok_sum+ng_sum, ans)

# # l b
# for i in range(0,k):
#     for j in range(1,k+1):
#         ok_sum = ok_csums[k][j] - ok_csums[i][j]
#         ng_sum = ng_cnt - (ng_csums[k][j] - ng_csums[i][j])
#         ans = max(ok_sum+ng_sum, ans)


# # r u
# for i in range(1,k+1):
#     for j in range(0,k):
#         ok_sum = ok_csums[i][k] - ok_csums[i][j]
#         ng_sum = ng_cnt - (ng_csums[i][k] - ng_csums[i][j])
#         ans = max(ok_sum+ng_sum, ans)


print(ans)

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

void dfs(int root, int node, vector<vector<int> >& adjlist, vector<int>& used){

    for(int i = 0; i < adjlist[node].size(); i++){
        if(used[adjlist[node][i]] == -1){
            used[adjlist[node][i]] = root;
            dfs(root, adjlist[node][i], adjlist, used);
        }
    }
}

int main(){

    int n, m; cin >> n >> m;

    vector<vector<int> > adjlist(n);               

    //入力
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;                   // a ←→ b に辺がある
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
        
    }

    vector<int> used(n, -1);

    for(int i = 0; i < n; i++){
        if(used[i] == -1){
            used[i] = i;
            dfs(i, i, adjlist, used);
        }
    }

    /*for(int i = 0; i < n; i++){
        cout << i << " " << used[i] << endl;
    }*/

    //質問
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int a, b; cin >> a >> b;
        
        
        if(used[a] == used[b]) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 13420
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}
int n;
vi a,b,asum,bsum;
int f(){
    int ret = a.back();
    rep(i,n-1){
        int num = (n-i)/2;
        //cout << i << " " << num << endl;
        int p = asum[i+num-1];
        if(i)p -= asum[i-1];
        int q = 0;
        if(i+num+1 < n)q += bsum[i+num+1];
        int t = a[i+num];
        if((n-i-1)%2)t = b[i+num];
        ret = max(ret, 2*p + t + 2*q);
        //cout << 2*p << " " << t << " " << 2*q << endl;
    }
    return ret;
}

signed main(void) {
    int i,j;
    int l;
    cin >> l >> n;
    a = b = vi(n);
    rep(i,n)cin >> a[i],b[i] = l - a[i];

    asum = a;
    bsum = b;
    rep(i,n-1)asum[i+1] += asum[i];
    rev(i,n-1)bsum[i] += bsum[i+1];
    //rep(i,n)cout << " " << a[i];cout << endl;
    //rep(i,n)cout << " " << b[i];cout << endl;
    int ans = f();
    //cout << endl;
    swap(a,b);
    swap(asum,bsum);
    reverse(all(a));
    reverse(all(b));
    reverse(all(asum));
    reverse(all(bsum));

    ans = max(ans, f());
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <list>
#include <algorithm>
#include <queue>


//g++ -std=c++11 IPL.cpp -o IPL
using namespace std;


int main(int argc, char**argv){
  string chips;
  cin >> chips;
  int num =0;
  int length = chips.size();
  for(int i = 0; i+1 <length; i++){
    if(chips[i] != chips[i+1]){
      num++;
    }else{
      continue;
    }




  }

  cout << num;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	string s, t;
	bool flg = false;
	ll i;
	in(s);
	in(t);

	for(i=s.size()-t.size();i>=0;i--) {
		
		if (s[i] == t[0] || s[i] == '?') {
			flg = true;
			rep(j, 1, t.size()) {
				if (s[i + j] != t[j] && s[i + j] != '?') {
					flg = false;
					break;
				}
			}
			if (flg) {
				break;
			}
		}
	}
	if (!flg) {
		outn("UNRESTORABLE");
		return 0;
	}

	rep(j, 0, s.size()) {
		if (j == i) {
			out(t);
		}
		else if (j < i || j >= i + t.size()) {
			if (s[j] == '?') {
				out("a");
			}
			else {
				out(s[j]);
			}
		}
	}
	outn("");

	return 0;


}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    o = list(input().rstrip())
    e = list(input().rstrip())

    ans = ""

    for i in range(len(o)):
        ans += o[i]
        if i < len(e):
            ans += e[i]


    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;


int main() {

	multimap<int,int>v;
	int n, m,x,y;
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> x >> y;
		if (x <= m)
		{

			v.insert({ x,y });
		}
	}
	priority_queue<int> la;
	int days = 0,tot=0;
	for (int i = 0;i <=m;i++) {
		typedef std::multimap<int, int>::iterator MMAPIterator;
		std::pair<MMAPIterator, MMAPIterator> result =v.equal_range(i);
		for (MMAPIterator it = result.first; it != result.second; it++) {
			la.push(it->second);
		}
		if (!la.empty()) {
			tot += la.top();
			la.pop();
		}
	}

	cout << tot;
	return 0;
}

Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N, 0);
  vector<bool> B(N, false);
  for (ll i = 0; i < M; i++)
  {
    ll p;
    string S;
    cin >> p >> S;
    p--;

    if (S == "AC")
      B.at(p) = true;
    else if (!B.at(p))
      A.at(p)++;
  }

  ll x = 0, y = 0;
  for (ll i = 0; i < N; i++)
  {
    if (B.at(i))
    {
      x++;
      y += A.at(i);
    }
  }
  cout << x << " " << y << endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main implements Runnable
{
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int k=sc.nextInt();
        int s=sc.nextInt();
        int d[]=new int[n];
        int mx=1000000000;
        for (int i = 0; i < k; i++) {
			d[i]=s;
		}
        for (int i = k; i < n; i++) {
			d[i]=s+1;
			if(d[i]>mx)d[i]=1;
		}
        
        for (int i = 0; i < d.length; i++) {
            out.print(d[i]+" ");			
		}
//        out.print();
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int x,y;
    P(int x,int y) {
    	this.x=x;
    	this.y=y;
    }

    public int compareTo(P p){
        return y-p.y;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  int n;
  while(cin >> n, n) {
    int t[n][n + 1];
    rep(i, n)rep(j, n + 1) cin >> t[i][j];

    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    rep(i, 1 << n) {
      rep(j, n) {
        if (!(i & (1 << j))) {
          minch(dp[i + (1 << j)], dp[i] + t[j][0]);
          rep(k, n) {
            if (i & (1 << k)) minch(dp[i + (1 << j)], dp[i] + t[j][k + 1]);
          }
        }
      }
    }

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

  return 0;
}

Measured memory_bytes: 3368