akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import copy

N = int(input())

a_list = []
for n in range(N):
    a_list.append(int(input()))

a_list_copy = copy.copy(a_list)
maximum_list = []
for i in range(2):
    maximum_list.append(max(a_list_copy))
    a_list_copy.remove(max(a_list_copy))

if maximum_list[0] == maximum_list[1]:
    for a in a_list:
        print(maximum_list[0])
else:
    for a in a_list:
        if a == maximum_list[0]:
            print(maximum_list[1])
        else:
            print(maximum_list[0])

Measured memory_bytes: 14560
#include <cstdio>

int L1 = 11 * 60, L2 = 14 * 60 + 59;
int D1 = 18 * 60, D2 = 20 * 60 + 59;
int M1 = 21 * 60, M2 = 01 * 60 + 59;

int check(int t) {
	if(t >= L1  && t <= L2) {
		return 0;
	}
	if(t >= D1  && t <= D2) {
		return 1;
	}
	if(t >= M1  || t <= M2) {
		return 2;
	}
	return -1;
}

int main() {
	int n;
	while(~scanf("%d", &n) && n) {
		
		int N[3] = {0}, C[3] = {0};
		int a, b, c;
		for(int i = 0; i < n; i++) {
			scanf("%d%*c%d%d",&a, &b, &c);
			int t1 = a * 60 + b;
			int t2;
			if( b <= c) {
				t2 = a * 60 + c;
			}else {
				t2 = (a +  1)  * 60 + c;
			}
			int t = check(t1);
			if(t != -1) {
				N[t]++;
				if(t2 - t1 <= 8) {
					C[t]++;
				}
			}
		}
		char s[3][20] = {"lunch", "dinner", "midnight"};
		for(int i = 0; i < 3; i++) {
			printf("%s ", s[i]);
		//	printf("%d %d\n", N[i], C[i]);
			if(!N[i]) {
				puts("no guest");
			}else {
				printf("%d\n", C[i] * 100 / N[i]);
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 1040
N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * N for _ in range(1 << N)]
DY = [[0] * N for _ in range(1 << N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[k][i] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[k][i] = d * P[i]

ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
    PC[i] = PC[i^1] + 1 if i % 2 else PC[i//2]

RA = []
for i in range(1 << N):
    t = []
    for j in range(N):
        if i & (1 << j):
            t.append(j)
    RA.append(t)

mm = (1 << N) - 1
for i in range(1 << N):
    m = i ^ mm
    j = m
    dxi = DX[i]
    pci = PC[i]
    while 1:
        dyj = DY[j]
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(dxi[k], dyj[k])
        
        pc = pci + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)


print(*ANS, sep = "\n")


Measured memory_bytes: 89020
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int k = scanner.nextInt();
        final int x = scanner.nextInt();

        for (int i = x - k + 1; i < x + k; i++) {
            System.out.print(i + " ");
        }
    }
}


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

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

  for(int i=0; i<N; i++){
    vector<int> balls(10);
    for(int j=0; j<10; j++) cin >> balls[j];

    priority_queue<int> A, B;
    A.push(0); B.push(0);

    bool flag = true;
    for(int j=0; j<10; j++){
      if(A.top() > balls[j] && B.top() > balls[j]){
        if(flag) cout << "NO" << endl; 
        flag = false;
      } else if (A.top() < balls[j] && B.top() > balls[j]){
        A.push(balls[j]);
      } else if (A.top() > balls[j] && B.top() < balls[j]){
        B.push(balls[j]);
      } else {
        if(A.top() > B.top()){
          A.push(balls[j]);
        } else {
          B.push(balls[j]);
        }
      }
    }

    if(flag) cout << "YES" << endl;
  }
}
  
  


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
  int Q;
  cin>>Q;
  int c[100],a[100],n[100];
  for(int i=0;i<Q;i++){
    cin>>c[i]>>a[i]>>n[i];
  }
  int team[100];
  for(int i=0;i<Q;i++){
    int lea=min(c[i],min(a[i],n[i]));
    team[i]=lea;
    c[i]-=lea;
    a[i]-=lea;
    n[i]-=lea;
    if(n[i]==0){
      int sec=min(c[i]/2,a[i]);
      team[i]+=sec;
      c[i]-=sec*2;
      a[i]-=sec;
      if(a[i]==0){
        team[i]+=a[i]/3;
      }
    }
    if(a[i]==0){
      team[i]+=c[i]/3;
    }
    cout<<team[i]<<endl;
  }
  /*int N,R,L;
  cin>>N>>R>>L;
  int d[1000000],t[1000000],x[1000000];
  for(int i=0;i<R;i++){
    cin>>d[i]>>t[i]>>x[i];
  }*/
  return 0;
}


Measured memory_bytes: 3116
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    x = I()
    if x in [3,5,7]:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    s = list(map(int,S()))
    ans = float("inf")
    for i in range(len(s)-2):
        x = 100*s[i]+10*s[i+1]+s[i+2]
        ans = min(ans,abs(x-753))
    print(ans)
    return

#C
def C():
    n = list(map(int,S()))
    l = len(n)
    dp = [[[0 for k in range(16)] for j in range(2)] for i in range(l+1)]
    dp[0][0][0] = 1
    for i in range(l):
        for j in range(2):
            for k in range(9):
                x = 9 if j else n[i]
                for d in range(x+1):
                    if d == 3:
                        f = 1
                    elif d == 5:
                        f = 2
                    elif d == 7:
                        f = 4
                    else:
                        if k == 0 and d == 0:
                            f = 0
                        else:
                            f = 8
                    dp[i+1][j or d < n[i]][k|f] += dp[i][j][k]
    ans = 0
    for i in range(2):
        ans += dp[l][i][7]
    print(ans)
#D
def D():
    def factorial(n):
        if n <= 3:
            return [n]
        l = []
        i = 2
        m = n
        while i**2 <= n:
            while m%i == 0:
                l.append(i)
                m //= i
            i += 1
        if m != 1:
            l.append(m)
        return l

    n = I()
    d = defaultdict(int)
    for i in range(2,n+1):
        l = factorial(i)
        for j in l:
            d[j] += 1
    a3 = 0
    a5 = 0
    a15 = 0
    a25 = 0
    a75 = 0
    for i in d.keys():
        if d[i] >= 74:
            a75 += 1
        if d[i] >= 24:
            a25 += 1
        if d[i] >= 14:
            a15 += 1
        if d[i] >= 4:
            a5 += 1
        if d[i] >= 2:
            a3 += 1
    ans = a75+(a3-1)*a25+(a5-1)*a15+(a3-2)*a5*(a5-1)//2
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin >> s;
  string str = s.substr(5,2);
  const char* buf = str.c_str();
  int m = atoi(buf);
  cout << ((m<=4) ? "Heisei" : "TBD") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    int h,w; cin >> h >> w;
    int n; cin >> n;
    vector<int> a(n);
    vector<vector<int>> ans(h,vector<int>(w,0));
    rep(i,n) cin >> a.at(i);
    int x = 0;
    rep(i,h){
        if(i%2 == 0){
            for(int j=0;j<w;j++){
                a.at(x)--;
                ans.at(i).at(j) = x+1;
                if(a.at(x)==0) x++;
            }
        }else{
            for(int j=w-1;j>=0;j--){
                a.at(x)--;
                ans.at(i).at(j) = x+1;
                if(a.at(x) == 0) x++;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            cout << ans.at(i).at(j) << " " ;
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N, M;
  cin>>N>>M;
  
  vector<int> arrow[100010];
  int from,to;
  for(int i=0;i<M;i++){
    cin>>from>>to;
    arrow[from-1].push_back(to-1);
  }
  int start,goal;
  cin>>start>>goal;
  start--; goal--; //0index
  bool arr[100010]={false};
  int attempt[100010];
  
  arr[start]=true;
  attempt[start]=0;
  queue<pair<int,int>> q;
  q.push({start,0});

  while(!q.empty()&&arr[goal]==false){
    pair<int,int> tmp=q.front();
    q.pop();
    int pos=tmp.first,time=tmp.second;
    for(auto next:arrow[pos]){
      if((time+1)%3==0){
        if(arr[next]) continue;
        arr[next]=true;
        attempt[next]=(time+1)/3;
      }
      q.push({next,time+1});
    }
  }
  
  if(!arr[goal]) cout<<-1<<endl;
  else cout<<attempt[goal]<<endl;

  return 0;
}



Measured memory_bytes: 825928
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    s = input()
    bef = s[0]
    cur = ""
    ans = 1
    for c in s[1:]:
        cur += c
        if cur != bef:
            ans += 1
            bef = cur
            cur = ""
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3500
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
b = Counter(a)

ans = 0
for i in b:
    ans += b[i] * (b[i]-1) // 2
    
for i in a:
    if b[i] < 2:
        sa = 0
    else:
        sa = b[i] - 1
    print(ans - sa)

Measured memory_bytes: 89804
#include<bits/stdc++.h>
int main()
{
	int x ,a ,b ,c ,cnt=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i = 0; i <= a; i++)
	{
		for(int j = 0; j <= b; j++)
		{
			for(int k = 0; k <= c; k++)
			{
				if(i*500 + j*100 + k*50 == x)
					cnt++;
			}
		}
	}
	printf("%d",cnt);
	return 0;
 } 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static class Node<E> {
		public E value;
		public Node<E> next;		
		public Node(E value) {
			this.value = value;
			this.next = null;
		}
	}

	static class SimpleQueue<E> {
		
		private Node<E> head;
		private Node<E> tail;
		private int size;
		
		public SimpleQueue() {
			size = 0;
			head = null;
			tail = null;
		}
		
		public int getSize() {
			return size;
		}
		
		public boolean isEmpty() {
			return size == 0;
		}
		
		public void enqueue(E element) {
			Node<E> node = new Node<E>(element);
			if (head == null && tail == null) {
				head = tail = node;
			} else {
				tail.next = node;
				tail = node;
			}
			size++;
		}
		
		public E dequeue() {			
			if (isEmpty()) {
				return null;
			}
			E element = head.value;
			head = head.next;
			if (head == null) {
				tail = null;
			}
			size--;
			return element;			
		}
		
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("[");
			Node<E> current = head;
			while (current != null) {
				sb.append(current.value);
				current = current.next;
				if (current != null) {
					sb.append(", ");
				}
			}			
			sb.append("](");
			if (tail != null) {
				sb.append(tail.value);
			}
			sb.append(")");
			return sb.toString();
		}
	}
	
	static class Process {		
		public String name;
		public int time;		
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);		
		int n = sc.nextInt();
		int q = sc.nextInt();		
		SimpleQueue<Process> queue = new SimpleQueue<Process>();
		for (int i = 0; i < n; i++) {
			queue.enqueue(new Process(sc.next(), sc.nextInt()));
		}
		sc.close();

		int total = 0;
		while (!queue.isEmpty()) {			
			Process process = queue.dequeue();
			int time = process.time;
			total += Math.min(time, q);
			if (time > q) {
				process.time = time - q;
				queue.enqueue(process);
			} else {
				System.out.println(process.name + " " + total);
			}
		}
	}
}



Measured memory_bytes: 76724
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn usize() -> usize {
    read()
}

fn vec_usize(n: usize) -> Vec<usize> {
    let mut vec = Vec::new();
    for _ in 0..n {
        vec.push(usize())
    }
    vec
}

fn main() {
    let mut ns = vec_usize(3);
    ns.sort();
    if ns == vec![5, 5, 7] {
        println! {"YES"};
    } else {
        println! {"NO"};
    }
}


Measured memory_bytes: 2008
import sys
a = [input().split() for l in range(3)]
n = int(input())
b = [int(input())for i in range(n)]

for i in range(3):
    for j in range(3):
        if int(a[j][i]) in b :
            a[j][i]=0



i = 0
for i in range(3):
    if (a[i][0]==a[i][1]==a[i][2]) | (a[0][i]==a[1][i]==a[2][i]):
        print("Yes")
        sys.exit()
if (a[0][0]==a[1][1]==a[2][2]) | (a[0][2]==a[1][1]==a[2][0]):
    print("Yes")
    sys.exit()
else:
    print("No")

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

ll gcd(ll a, ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main(){

    int a,b;cin>>a>>b;

    cout<<lcm(a,b)<<"\n";

    return 0;

}

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

int main(){
  string s,t;
  cin >> s >> t;
  int count = 0;
  for(int i=0;i<s.length();i++){
    if(s.at(i) != t.at(i)){
      count++;
    }
  }
  cout << count << endl;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

struct Card {
	int value; char mark;
};

bool cmp(const Card &l, const Card &r) {
	return l.value < r.value;
}

void BubbleSort(Card a[], int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (a[j].value < a[j-1].value) {
				swap(a[j], a[j-1]);
			}
		}
	}
}

void SelectionSort(Card a[], int n) {
	for (int i = 0; i < n; i++) {
		int min_index = i;
		for (int j = i; j < n; j++) {
			if (a[j].value < a[min_index].value) {
				min_index = j;
			}
		}
		swap(a[i], a[min_index]);
	}
}

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

	int n;
	cin >> n;
	Card A[36], B[36], stable[36];
	REP(i, n) {
		cin >> A[i].mark >> A[i].value;
		stable[i].mark = B[i].mark = A[i].mark;
		stable[i].value = B[i].value = A[i].value;
	}
	stable_sort(stable, stable + n, cmp);
	bool flg = true;
	BubbleSort(A, n);
	REP(i, n) {
		cout << A[i].mark << A[i].value << (i == n-1 ? '\n' : ' ');
		if (A[i].mark != stable[i].mark) flg = false;
	}
	cout << (flg ? "Stable" : "Not stable") << endl;
	flg = true;
	SelectionSort(B, n);
	REP(i, n) {
		cout << B[i].mark << B[i].value << (i == n-1 ? '\n' : ' ');
		if (B[i].mark != stable[i].mark) flg = false;
	}
	cout << (flg ? "Stable" : "Not stable") << endl;

	return 0;
}



Measured memory_bytes: 3184
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s := r.nextString()

	ans := true
	for i := range s {
		if (i+1)%2 == 0 {
			if s[i] == 'R' {
				ans = false
				break
			}
		} else {
			if s[i] == 'L' {
				ans = false
				break
			}
		}
	}
	fmt.Fprintln(stdout, []string{"No", "Yes"}[b2i(ans)])
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int k,x;
	cin >> k >>x;
	for(int i = x - k + 1; i < x + k; i++) {
		cout << i << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[]args) throws IOException {
    BufferedReader b= new BufferedReader(new InputStreamReader(System.in));
    String s;
    
    while ((s = b.readLine()) != null) {
      char[]a = s.toCharArray();
      for (int i = 0; i < a.length/2; i++) {
        swap(i, a.length-i-1, a);
      }
      System.out.println(String.valueOf(a));
    }
  }
  
  static void swap(int i, int j, char[]a) {
    char temp = a[i];
    a[i] = a[j];
    a[j] = temp;
  }
}

Measured memory_bytes: 24036
package main

import (
    "fmt"
)

func main() {
    var (
		a	string
		count = 0
	)
	fmt.Scan(&a)
	for i := 0; i < len(a); i++ {
		if a[i] == '1' {
			count ++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 1768
#include <iostream>

using namespace std;

int a, b;
int deci[5];

bool per(int n)
{
    for (int i = 0; i < 5; i++) {
        deci[4-i] = n%10;
        n /= 10;
    }

    if (deci[0] == deci[4] && deci[1] == deci[3]) return true;
    else return false;
}

void solve()
{
    int ans = 0;
    for (int i = a; i <= b; i++) {
        if (per(i)) ans++;
    }

    cout << ans << endl;
}

int main()
{
    cin >> a >> b;

    solve();

    return 0;
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main(){ // 包除定理
    int n, m;
    cin >> n >> m;
    mint ans = 0;
    for(int i = 0; i < n+1; i++){
        mint now = c(n,i); //一致している場所(個数i)の選び方
        now *= c.p(m,n); //Aは自由
        now *= c.p(m-i,n-i); //Bの一致しているところ以外の並べ方
        if(i&1) now = -now;
        ans += now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18616
n, m = map(int, input().split(' '))
if n == 1:
    start = 0
else:
    start = 10**(n-1)
end = 10**n

query = [[0]*2 for i in range(m)]

for i in range(m):
    query[i][0], query[i][1] = map(int, input().split(' '))

for i in range(start, end):
    flag = True
    i_str = str(i)
    for q in query:
        s = q[0]
        c = str(q[1])
        if i_str[s-1] != c:
            flag = False
            break
    if flag:
        ans = i
        break
        
if flag is False:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3064
using System;
class c
{
    static void Main()
    {
        var b = Console.ReadLine();
        switch (b)
        {
            case ("A"):
                Console.WriteLine("T");
                break;
            case ("T"):
                Console.WriteLine("A");
                break;
            case ("G"):
                Console.WriteLine("C");
                break;
            case ("C"):
                Console.WriteLine("G");
                break;                
            default:
                break;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    pr(c,a,b);
}

Measured memory_bytes: 256
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::collections::{HashMap, BinaryHeap, BTreeMap};

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// 可愛い可愛い、お手製のライブラリ達
macro_rules! p {
    ($t:expr) => {
        println!("{}", $t);
    };
}
macro_rules! debug {
    ($t:expr) => {
        println!("{:?}", $t);
    };
}
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    gcd(b, a % b)
}
fn lcm(a:usize, b:usize) -> usize {
    a / gcd(a, b) * b
}

use std::cmp::max;

// エントリーポイント
fn main() {
    input! {
        N:usize,
        A:[usize; N],
    }
    let max_left = {
        let mut max_v = vec![A[0]];
        for a in A.iter().skip(1) {
            let last = *max_v.last().unwrap();
            max_v.push(max(last, *a));
        }
        max_v
    };
    let max_right = {
        let mut max_v = vec![*A.last().unwrap()];
        for a in A.iter().rev().skip(1) {
            let last = *max_v.last().unwrap();
            max_v.push(max(last, *a));
        }
        max_v.reverse();
        max_v
    };
    let max_list = {
        let mut max_v = vec![max_right[1]];
        for n in 0..N {
            if N <= n + 2 {break;}
            max_v.push(max(max_left[n], max_right[n + 2]));
        }
        max_v.push(max_left[max_left.len() - 2]);
        max_v
    };
    for v in max_list {
        p!(v);
    }
}


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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)


// #define printf(a,...) if(0){}
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);

int main () {
  ios::sync_with_stdio(0); cin.tie(0);
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll x,n;
    cin >> x >> n;
    vector<ll> A(n);
    for (auto& xx : A) cin >> xx;
    set<int> s(A.begin(), A.end());
    int ans = 0;
    for (int i = 0; i < 102; ++i) {
      if (!s.count(x-i)) {
        ans = x - i;
        break;
      }
      if (!s.count(x+i)) {
        ans = x + i;
        break;
      }
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int N; cin>>N;
  ll h = -1;
  ll t;
  ll count = 0;
  ll r = 0;
  REP(i,N){
    cin >> t;
    if(h<t){
      r = max(count,r);
      count = 0;
    }else{
      count++;
    }
    h = t;
  }
  r = max(count,r);
  cout << r;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<lint>B(N);
	for (int i = N - 1; i >= 0; i--) {
		lint sum = 0;
		lint now = i+1;
		while (1) {
			sum += B[now-1];
			now += i+1;
			if (now > N) {
				break;
			}
		}
		if (sum % 2 != A[i]) {
			B[i]++;
		}
	}
	lint num = 0;
	rep(i, N) {
		if (B[i] != 0) {
			num++;
		}
	}
	cout << num << endl;
	rep(i, N) {
		if (B[i] != 0) {
			cout << i + 1;
		}
		if (i != N - 1) {
			cout << ' ';
		}
		else {
			cout << endl;
		}
	}
}

Measured memory_bytes: 4096
/*
Author : N_o_o_B
Created : April 22 2020 22:38:59 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    string s;
    cin >> s;
    bool ok = (s[0]=='A');
    int cnt = 0;
    rep(i,2,sz(s)-2){
        cnt += (s[i]=='C');
        if(s[i]!='C') ok &= (s[i]>='a' and s[i]<='z');
    }
    rep(i,1,1){
        ok &= (s[i]>='a' and s[i]<='z');
    }
    ok &= (s.back() >= 'a' and s.back() <= 'z');
    ok &= (cnt==1);
    cout << (ok ? "AC":"WA") << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,n-1):
    if p[i]>p[i-1]:
        if p[i+1]>p[i]:
            count=count+1
    elif p[i]>p[i+1]:
        if p[i-1]>p[i]:
            count+=1
print(count)

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){

  int X,Y;
  cin >> X >> Y;
  
  bool flag = false;
  int c=0,t=0;
  for(c=0; c<101; c++){
    for(t=0; c+t<101; t++){
      if(X==(c+t)){
        if(Y==(c*2+t*4)){
          flag = true;
        }
      }
    }
  }
  
  if(flag){
    cout << "Yes";
  }else{
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 3628
from collections import deque
SA = input()
SB = input()
SC = input()

def calculate(SA,SB,SC):
    a1 = list(SA)
    a2 = list(SB)
    a3 = list(SC)

    q1 = deque()
    for a in a1:
        q1.append(a)

    q2 = deque()

    for a in a2:
        q2.append(a)

    q3 = deque()

    for a in a3:
        q3.append(a)

    arr = [q1,q2,q3]
    stt = ["A","B","C"]

    currentIndex = 0

    while currentIndex >= 0:
        if len(arr[currentIndex]) == 0:
            break

        currentValue = arr[currentIndex].popleft()

        if currentValue == "a":
            currentIndex = 0
            continue

        if currentValue == "b":
            currentIndex = 1
            continue

        if currentValue == "c":
            currentIndex = 2
            continue

    print(stt[currentIndex])


calculate(SA,SB,SC)

Measured memory_bytes: 9316
import random

nums = input().split()

#print(nums)
#A = nums[0]
#B = nums[1]
#C = nums[2]
a = int(nums[0])
b = int(nums[1])
c = int(nums[2])
#print(a)
K = input()
k = int(K)

#print(type(a))

#print(k)

cnt = 0

#print(type(cnt))

while a >= b:
  cnt +=1
  b *= 2
  #print(b)

while b >= c:
  cnt += 1
  c *= 2
  #print(c)
  
#if cnt

  
if cnt <= k:
  print("Yes")
else:
  print("No")

	

#for hoge in range(1,k +1):
#	print(hoge)
#print(random.choice(nums))

#print(A)

Measured memory_bytes: 9484
# D - People on a Line
from collections import deque
n,m=map(int,input().split())
dist=[None]*n
edge=[[] for i in range(n)]

for i in range(m):
    l,r,d=map(int,input().split())
    edge[l-1].append((r-1,d))
    edge[r-1].append((l-1,-d))

for i in range(n):
    q=deque()
    if dist[i]==None:
        dist[i]=0
        q.append(i)
    while q:
        cur=q.popleft()
        for nx,d in edge[cur]:
            if dist[nx]==None:
                dist[nx]=dist[cur]+d
                q.append(nx)
            elif dist[nx]!=dist[cur]+d:
                print('No')
                exit()
print('Yes')

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

int main(){
    int n,m,miss=0,mn=10;cin>>n>>m;
    map<int,int> s;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;mn=min(mn,a);
        if(a==1&&b==0&&n!=1){
                miss++;
                break;
            }
        else if(s.count(a)){
            if(s[a]==b) continue;
            else{
                miss++;
                break;
            }
        }
        else s[a]=b;
    }
    if(miss!=0) cout<<-1<<endl;
    else{
        int ans=0;
        if(mn!=1) ans+=pow(10,n-1);
        if(m==0&&n==1) ans=0;
        for(auto p : s){
            auto k = p.first;
            auto t = p.second;
            ans+=pow(10,n-k)*t;
        }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int a[] = new int[M];
		int b[] = new int[M];
		int c[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			for(int j = 0; j < b[i]; j++) {
				c[i] |= 1 << (sc.nextInt() - 1);
			}
		}
		
		int dp[] = new int[1 << N];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		
		for(int i = 0; i < 1 << N; i++) {
			for(int j = 0; j < M; j++) {
				if(dp[i] != Integer.MAX_VALUE) {
					int t = i | c[j];
					int cost = dp[i] + a[j];
					dp[t] = Math.min(dp[t], cost);
				}
			}
		}
		
		System.out.println(dp[(1 << N) - 1] == Integer.MAX_VALUE ? -1 : dp[(1 << N) - 1]);
	}
}


Measured memory_bytes: 32068
#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;


#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
	
	int t=1;
	//cin>>t;
	while(t--){
		string fw,bc,in;
		fw.clear();
		bc.clear();
		cin>>in;
		vector <pair <int,pair <int,char> > >  v;
		int q;
		cin>>q;
		while(q--)
			{	int x;
				cin>>x;
				if(x==1)
					{
						v.push_back({1,{1,'a'}});
					}
				else
					{
                         int y;char w;
                         cin>>y>>w;
                         v.push_back({x,{y,w}});
					}
			}
		int c=0;
		reverse(v.begin(),v.end());
		for(auto it:v)
			{
				if(it.first==1)
					{
						++c;
						c%=2;
					}
				else
					{
						if(c==1)
							{
								if(it.second.first==1)
								{
									bc+=it.second.second;
								}
								else
								{
									fw+=it.second.second;
								}
							}
						else
						{
							if(it.second.first==2)
								{
									bc+=it.second.second;
								}
								else
								{
									fw+=it.second.second;
								}
						}
					}
			}
		reverse(bc.begin(),bc.end());
		if(c%2==1)
			reverse(in.begin(),in.end());
		cout<<(fw+in+bc)<<'\n';

	}



return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
    int n; cin >> n;
    int ans = 0;
    vector<int> a(n);
    vector<int> b(n + 1, 0);
    REP(i, n){
        cin >> a[i];
        if(a[i] > n){
            a[i] = 0;
            ans++;
        }
    }
    REP(i, n){
        if(a[i] != 0){b[a[i]]++;}
    }
    FOR(i, 0, n+1){
        if((b[i] != 0) && (b[i] != i)){
            b[i] > i ? (ans += b[i] - i) : (ans += b[i]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;

int main(void) {
  int i, j, k, l, n, p, q, rp, rq, np, nq;
  scanf("%d%d%d", &n, &k, &l);
  int ufr[n], uft[n];
  for(i = 0; i < n; ++i) ufr[i] = uft[i] = i;
  for(i = 0; i < k; ++i) {
    scanf("%d%d", &p, &q);
    rp = 0, rq = 0, np = --p, nq = --q;
    while(ufr[np] != np) rp++, np = ufr[np];
    while(ufr[nq] != nq) rq++, nq = ufr[nq];
    if(rp < rq) ufr[np] = nq;
    else ufr[nq] = np;
  }
  for(i = 0; i < l; ++i) {
    scanf("%d%d", &p, &q);
    rp = 0, rq = 0, np = --p, nq = --q;
    while(uft[np] != np) rp++, np = uft[np];
    while(uft[nq] != nq) rq++, nq = uft[nq];
    if(rp < rq) uft[np] = nq;
    else uft[nq] = np;
  }
  pair<int, int> cnt[n], ans[n];
  for(i = 0; i < n; ++i) {
    np = i, nq = i;
    while(ufr[np] != np) np = ufr[np];
    while(uft[nq] != nq) nq = uft[nq];
    cnt[i] = ans[i] = {np, nq};
  }
  sort(ans, ans + n);
  for(i = 0; i < n; ++i) printf("%d ", upper_bound(ans, ans + n, cnt[i]) - lower_bound(ans, ans + n, cnt[i]));
  return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,z,w,a[2000];

int main(){
  scanf("%d %d %d",&n,&z,&w);
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  if(n==1)
    printf("%d\n",abs(w-a[0]));
  else
    printf("%d\n",max(abs(a[n-1]-a[n-2]),abs(w-a[n-1])));
}
  

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

int cn[4] = {10,50,100,500};
int cc[4];
int ca[4];

int getcc(int aa){
  int res=0;
  for(int i=3;i>=0;i--){
    cc[i]=aa/cn[i];
    aa%=cn[i];
    res+=cc[i];
  }
  return res;
}

int main(){
  int c[4];
  int ans;
  int n;
  cin>>n;
  while(1){
    ans = 1000;
    for(int i=0;i<4;i++)cin>>c[i];
   
    for(int x=0;x<=c[0];x++)
      for(int y=0;y<=c[1];y++)
        for(int z=0;z<=c[2];z++)
          for(int w=0;w<=c[3];w++){
            int m=x*cn[0]+y*cn[1]+z*cn[2]+w*cn[3];
            if(m<n) continue;
            int mc = getcc(m-n);
            if((cc[0]&&x)||(cc[1]&&y)||(cc[2]&&z)||(cc[3]&&w)) continue;
            int cs=c[0]-x+c[1]-y+c[2]-z+c[3]-w;
            if(ans>mc+cs){
              ans=mc+cs;
              ca[0]=x;
              ca[1]=y;
              ca[2]=z;
              ca[3]=w;

            }
          }
    
    for(int i=0;i<4;i++){
      if(ca[i]==0) continue;
      cout<<cn[i]<<" "<<ca[i]<<endl;
    }
    cin>>n;
    if(n==0) break;
    else cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define chushihua(x,y) memset(x,y,sizeof x)
using namespace std;
const int MAXX = 100000 + 10;
const double PI = 3.14159265358979323846;
const ll mod = 1000000007;
string s[10000];
int main() {
	int n, m;
	while (cin >> n>>m) {
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		sort(s, s + n);
		for (int i = 0; i < n; i++) {
			cout << s[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

const long long N_MAX=200001;
long long N;
long long A[N_MAX], B[N_MAX];
long long max1, max2;

int main(){
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    for (int i=0; i<N; i++){
        B[i] = A[i];
    }
    sort(B, B+N, greater<int>());
    max1 = B[0];
    max2 = B[1];
    for (int i=0; i<N; i++){
        if (A[i]==max1){
            cout << max2 << endl;
        } else {
            cout << max1 << endl;
        }
    }


}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;

typedef long long ll;

const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, k, r, s, p;

int main(){

    int n, r;

    cin >> n >> r;

    if(n >= 10) cout << r;

    else {
        
        cout << r + (100 * (10 -n));

    }

    return 0;

}

Measured memory_bytes: 256
#include <atcoder/all>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int n,q;


int main(){
    cin>>n>>q;
    auto fw = atcoder::fenwick_tree<long long>(n);
    REP(i,n){
        LL a;
        cin>>a;
        fw.add(i, a);
    }
    REP(i,q){
        LL a,c;
        int b;
        cin>>a>>b>>c;
        if(a==0){
            fw.add(b,c);
        }else{
            cout<<fw.sum(b,(int)c)<<endl;
        }
    }
}

Measured memory_bytes: 8220
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n, w;
    cin >> n >> w;
    vector<ll> weight(n);
    vector<ll> value(n);
    rep(i,n){
        cin >> weight.at(i) >> value.at(i);
    }

    vector<vector<ll>> dp(n+1, vector<ll>(100001));
    rep(i,n+1){
        rep(j,100001){
            dp.at(i).at(j) = 1e10;
        }
    }

    dp.at(0).at(0) = 0;

    rep(i,n){
        for(ll sum_v = 0; sum_v <= 100000; sum_v++){
            if(sum_v - value.at(i) >= 0){
                chmin(dp.at(i+1).at(sum_v), dp.at(i).at(sum_v - value.at(i)) + weight.at(i));
            }

            chmin(dp.at(i+1).at(sum_v), dp.at(i).at(sum_v));
        }
    }

    ll res = 0;
    rep(i,100001){
        if(dp.at(n).at(i) <= w) res = i;
    }
    cout << res << endl;

}


Measured memory_bytes: 80256