akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int n,both,number;
bool a[100010];
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
		a[i]=false;
	for(int i=1; i<=n; i++)
	{
		cin>>number;
		if(a[number]==true)both++;
		else a[number]=true;
	}
	if(both%2==1)both++;
	cout<<n-both;
	return 0;
}

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

struct comparepq{
  bool operator()(pair<int,int> a, pair<int,int> b){
    if(a.second != b.second){
      return a.second < b.second;
    }
    else{
      return a.first > b.first;
    }
  }
};

bool comparev(pair<int,int> a, pair<int,int> b){
  if(a.first != b.first){
    return a.first < b.first;
  }
  else{
    return a.second > b.second;
  }
}

vector<pair<int, int> > v;
priority_queue<pair<int, int>, vector<pair<int, int> >, comparepq> pq;

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    pair<int, int> p = make_pair(a,b);
    v.push_back(p);
  }
  sort(v.begin(), v.end(), comparev);
  long sal=0;
  int idx=0;
  for(int i=1; i<=M; i++){
    while(idx<N && v[idx].first<=i){
      pq.push(v[idx]);
      idx++;
    }
    if(!pq.empty()){
      sal+=pq.top().second;
      pq.pop();
    }
  }
  cout << sal << endl;
  return 0;
}

Measured memory_bytes: 2548
#include <iostream>
#define INF (1<<25)
#define MAX 1001
using namespace std;

template <typename T>
class queue{
  private:
    T array[MAX];
    int head, tail, n;
  public:
    queue(int n){
      head=tail=0;
      this->n = n;
    }

    void push(T value){
      if (head == (tail+1)%n)
        return ;
      array[tail] = value;
      tail = (tail+1)%n;
    }

    bool empty(){
      if (head == tail)
        return true;
      return false;
    }

    void pop(void){
      if (head == tail) return;
      head = (head+1)%n;
    }

    T front(void){
      return array[head];
    }
};
int graph[MAX][MAX];
bool isDiscoverd[100];
int dist[100];
int dim[MAX];

void bfs(int i){
  queue<int> searchQueue(MAX);
  searchQueue.push(i);
  while(!searchQueue.empty()){
    auto current = searchQueue.front();
    int k = dim[current];
    searchQueue.pop();
    isDiscoverd[current] = true;
    for (auto ite=graph[current] ; ite != graph[current]+k ; ++ite){
      dist[*ite] = min(dist[*ite], dist[current]+1);
      if (!isDiscoverd[*ite]) searchQueue.push(*ite);
    }
  }
}

int main(){
  int n;
  cin >> n;
  for (int i=0;i<n;++i){
    int id;
    cin >> id;
    cin >> dim[id];
    for(int j=0;j<dim[id];++j){
      int temp;
      cin >> temp;
      graph[id][j] = temp;
      isDiscoverd[id]=false;
    }
  }

  dist[1] = 0;
  for (int i=2;i<=n;++i)
    dist[i] = INF;

  bfs(1);

  for (int i=1;i<=n;i++){
    cout << i << " " << (dist[i]>=INF?-1:dist[i]) <<endl;
  }

  return 0;
}


Measured memory_bytes: 3480
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = ns()
    uf = UnionFind(n)

    for _ in range(m):
        x, y, z = ns()
        uf.union(x - 1, y - 1)

    ans = uf.group_count()
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81624
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
 int main()
{	
lli n,i,j;
cin >> n;
i=(n%10);
if(i==2 || i==4 || i==5 || i==7 || i==9){
	cout << "hon" << '\n';
}
else if(i==3)cout << "bon" << '\n';
else cout << "pon" << '\n';


return 0;}


Measured memory_bytes: 3556
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	string s;
	cin >> s;
	bool c = false;
	int pc = -1, pf;
	bool f = false;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'C' && (pc == -1 || i < pc) ) {
			c = true;
			pc = i;
		}
		if (s[i] == 'F') {
			f = true;
			pf = i;
		}
	}
	if ((c && f) && (pc < pf)) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():

    def walk(p, c):
        if visited[p]:
            return
        visited[p] = True
        cnt[p] += c
        for n in tree[p]:
            walk(n, cnt[p])

    setrecursionlimit(2000001)

    n, q = [int(x) for x in stdin.readline().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in stdin.readline().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)
    for _ in range(q):
        p, x = [int(x) for x in stdin.readline().split()]
        cnt[p] += x

    visited = [False] * (n + 1)
    walk(1, 0)

    for i in range(1, n + 1):
        print(cnt[i], end=" ")

main()


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

inline vector<ll> get(vector<ll> &s, ll x){
	vector<ll> ret;
	int ind = lower_bound(s.begin(), s.end(), x) - s.begin();
	if(ind != s.size())ret.push_back(s[ind]);
	if(ind != 0)ret.push_back(s[ind - 1]);
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int a, b, q;
	cin>>a>>b>>q;
	vector<ll> s(a), t(b);
	for(auto &x : s){
		cin>>x;
	}
	for(auto &x : t){
		cin>>x;
	}
	ll x;
	while(q--){
		cin>>x;
		vector<ll> vs = get(s, x);
		vector<ll> vt = get(t, x);
		ll ans = 1e18;
		for(auto xx : vs){
			for(auto yy : vt){
				ans = min(ans, abs(x - xx) + abs(xx - yy));
			}
		}
		for(auto xx : vt){
			for(auto yy : vs){
				ans = min(ans, abs(x - xx) + abs(xx - yy));
			}
		}
		cout<<ans<<'\n';
	}

	return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int, int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define ar array
//#define endl '\n'
#define FOR(i, s, e) for (int i = s; i < e; ++i)
#define FORL(i, s, e) for (ll i = s; i < e; ++i)
#define RFOR(i, s, e) for (int i = e - 1; i >= s; --i)
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define MOD 1000000007LL
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof a);

#ifdef TRACE
#define lol std::cout << "Calling " << __func__ << endl

#else
#define lol
#endif

ll modpow(ll a, ll b, ll m = MOD)
{
	a %= m;
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return res;
}
ll bpow(ll a, ll b)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll modinv(ll a, ll m = MOD) { return modpow(a, m - 2, m); }

void solve(int t)
{
	//	cout << "Case #" << t << ": ";
	int n,m,x;
	cin >> n >> m >> x;
	vector<vector<int>> a(n, vector<int>(m));
	vector<int> c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	int ans = INT_MAX;
	int all = 1 << n;
	for (int mask = 0; mask < all; mask++)
	{
		vector<int> level(m,0);
		int cost = 0;
		for (int i = 0; i < n; i++)
		{
			if ((mask >> i) & 1)
			{
				cost += c[i];
				for (int j = 0; j < m; j++)
				{
					level[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		for (int j = 0; j < m; j++)
		{
			if (level[j] < x)
				ok = false;
		}
		if (ok)
			ans = min(ans, cost);
	}
	if (ans == INT_MAX)
		cout << "-1" << endl;
	else
		cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef IOF
	freopen("alchemy_input.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	//cin >> t;
	for (int tc = 1; tc <= t; tc++)
		solve(tc);
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int c=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='o')
			c++;
	}
	if(c+15-s.length()>7)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 13;
int n, lvl[maxN], mx, nd;
vector<int> adj[maxN];
void dfs (int x, int p) {
    if (lvl[x] > mx) {
	mx = lvl[x];
	nd = x;
    }
    for (auto a : adj[x]) {
	if (a != p) {
	    lvl[a] = lvl[x] + 1;
	    dfs(a, x);
	}
    }
}

int main () {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
	int a, b;
	cin >> a >> b;
	adj[a].push_back(b);
	adj[b].push_back(a);
    }
    lvl[1] = 1;
    dfs(1, 1);
    mx = 0;
    lvl[nd] = 1;
    dfs(nd, nd);
    if (mx % 3 == 2)
	cout << "Second" << endl;
    else
	cout << "First" << endl;
    
}


Measured memory_bytes: 21376
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()
 
s = S()
gx,gy = Is()
l = s.split("T")
for i in range(len(l)):
    l[i] = len(l[i])
xlis,ylis = l[::2],l[1::2]
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
xlis.sort(reverse=True)
ylis.sort(reverse=True)
def calc(start,goal,lis):
    p = start
    for e in lis:
        if p < goal:
            p += e
        else:
            p -= e
    return p == goal
if calc(sx,gx,xlis) and calc(sy,gy,ylis):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3572
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer


object Main {

  case class ResidueRing(private val input: Long) {
    val representative: Long = ((input % ResidueRing.mod) + ResidueRing.mod) % ResidueRing.mod

    def +(that: ResidueRing): ResidueRing = ResidueRing(this.representative + that.representative)

    def -(that: ResidueRing): ResidueRing = ResidueRing(this.representative - that.representative)

    def *(that: ResidueRing): ResidueRing = ResidueRing(this.representative * that.representative)

    def unary_- : ResidueRing = ResidueRing(-this.representative)

  }

  type Stone = Int

  object ResidueRing {
    val mod: Long = (1e9 + 7).toLong
    val zero: ResidueRing = ResidueRing(0)
    val one: ResidueRing = ResidueRing(1)
  }

  def read(): (Int, IndexedSeq[Stone]) = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val stones = for (i <- 0 until n) yield sc.nextInt()
    (n, stones)
  }

  def solve(n: Int, stones: IndexedSeq[Stone]): Long = {
    val edges: Array[mutable.Set[Int]] = Array.fill(n)(mutable.Set.empty)
    val maxColor = 500000

    // indexを0から走査したとき、stoneを通った一番最近のindex
    val history: Array[Option[Stone]] = Array.fill(maxColor)(None)

    for ((stone, i) <- stones.zipWithIndex) {
      if (i >= 1) edges(i).add(i - 1) // 後ろへ辺を追加
      history(stone).foreach { oldI => //stones(oldI) == stones(i) = stone
        edges(i).add(oldI)
      }
      history(stone) = Some(i)
    }

    val dp: Array[ResidueRing] = Array.fill(n)(ResidueRing.zero)
    dp(0) = ResidueRing.one
    for (i <- 1 until n) {
      dp(i) = edges(i).toList.map(oldI => dp(oldI)).foldLeft(ResidueRing.zero)(_ + _)
    }
    dp(n-1).representative
  }

  def main(args: Array[String]): Unit = {
    val (n, stones) = read()
    println(solve(n, stones))
  }
}

Measured memory_bytes: 167748
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  char a[5];
  scanf("%s",a);
  qsort(a,4,sizeof(a[0]),strcmp);
  puts(a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[2]?"Yes":"No");
  return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstdio>

using std::endl;

#define ll long long int
#define FOR(a, s, n) for(int a = s; a < n; ++a)
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define MOD 1000000007
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std
#define asn ans

// 4byte データ
#define BIT_FLAG_1		(0x0001LL); // 2進数 : (0000 0000 0000 0001)
#define BIT_FLAG_2		(0x0002LL); // 2進数 : (0000 0000 0000 0010)
#define BIT_FLAG_4		(0x0004LL); // 2進数 : (0000 0000 0000 0100)
#define BIT_FLAG_8		(0x0008LL); // 2進数 : (0000 0000 0000 1000)
#define BIT_FLAG_16		(0x0010LL); // 2進数 : (0000 0000 0001 0000)
#define BIT_FLAG_32		(0x0020LL); // 2進数 : (0000 0000 0010 0000)
#define BIT_FLAG_64		(0x0040LL); // 2進数 : (0000 0000 0100 0000)
#define BIT_FLAG_128	(0x0080LL); // 2進数 : (0000 0000 1000 0000)
#define BIT_FLAG_256	(0x0020LL); // 2進数 : (0000 0000 0010 0000)
#define BIT_FLAG_512	(0x0040LL); // 2進数 : (0000 0000 0100 0000)
#define BIT_FLAG_1024	(0x0080LL); // 2進数 : (0000 0000 1000 0000)

ll F[123][10];
ll P[123][11];

ll N;

ll max = -INF;

ll now_bit;


int D[123];

ll count(ll bit)
{

	LEP(a, N) D[a] = 0;

	if ((bit & 1) != 0) LEP(a, N)	if (F[a][0]) D[a]++;
	if ((bit & 2) != 0) LEP(a, N)	if (F[a][1]) D[a]++;
	if ((bit & 4) != 0) LEP(a, N)	if (F[a][2]) D[a]++;
	if ((bit & 8) != 0) LEP(a, N)	if (F[a][3]) D[a]++;
	if ((bit & 16) != 0) LEP(a, N)	if (F[a][4]) D[a]++;
	if ((bit & 32) != 0) LEP(a, N)	if (F[a][5]) D[a]++;
	if ((bit & 64) != 0) LEP(a, N)	if (F[a][6]) D[a]++;
	if ((bit & 128) != 0) LEP(a, N)	if (F[a][7]) D[a]++;
	if ((bit & 256) != 0) LEP(a, N)	if (F[a][8]) D[a]++;
	if ((bit & 512) != 0) LEP(a, N)	if (F[a][9]) D[a]++;

	ll sum = 0;

	LEP(a, N)sum += P[a][D[a]];

	return sum;

}

void solve(ll now)
{
	if (now == 0)
		if (now_bit != 0)
			max = std::max(max, count(now_bit));

	if (now > 0)
	{
		now_bit <<= 1;

		solve(now - 1);

		now_bit += 1;

		solve(now - 1);

		now_bit >>= 1;

	}

}


int main()
{
	IN >> N;

	LEP(a, N)
	{
		LEP(b, 10)
		{
			IN >> F[a][b];
		}
	}

	LEP(a, N)
	{
		LEP(b, 11)
		{
			IN >> P[a][b];
		}
	}

	solve(10);

	OUT << max << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Integer []l = new Integer[N];
    for(int i= 0; i < N; i++) {
    	l[i] = sc.nextInt();
    }
    Arrays.sort(l, Collections.reverseOrder());
    int ans = 0;

    for(int i = 0; i< K; i++) {
    	ans += l[i];
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 35708
#include <iostream>
using namespace std;
int main()
{
	int n,a,b,c = 0;
	cin >> n;
	for(int i=0;i < n;i++)
	{
		cin >> a >> b;
		c+=(b + 1 - a);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
/* created   : 2019-08-11 14:45:09
 * accepted  : 2019-08-11 15:05:32
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> box(n + 1);
  for (int i = n; i >= 1; i--) {
    int t = 0;
    for (int j = i; j <= n; j += i) {
      t += box[j];
    }
    if (t % 2 != a[i]) {
      box[i]++;
    }
  }
  trace(box);
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (box[i] == 1) {
      ans.push_back(i);
    }
    else if (box[i] > 1) {
      cout << -1 << "\n";
      return;
    }
  }
  trace(ans);
  int na = ans.size();
  cout << na << "\n";
  for (int i = 0; i < na; i++) {
    cout << ans[i] << (i == na - 1 ? "\n" : " ");
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<string> G(H);
    for(int i=0; i<H; i++){
        cin >> G[i];
    }
    vector<vector<int>> suzu(H, vector<int> (W,-1));
    for(int k=0; k<100; k++){
        for(int i=0; i<H; i++){
            for(int j=W-1; j>=0; j--){
                if(G[i][j] == 'c' and suzu[i][j] == -1){
                    suzu[i][j] = k;
                }
                if(j > 0){
                    G[i][j] = G[i][j-1];
                }
            }
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << suzu[i][j] << (j!=W-1 ? " " : "\n");
        }
    }
    return 0;
}



Measured memory_bytes: 3284
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float A,B;
float a;
cin>>A>>B;
a=floor(A*(100/8));
while (1){
    if(floor(a*0.08)==A and floor(a*0.1)==B){
        break;
    }
    else if(floor(a*0.08)>A){
        a=-1;
        break;
    }
    else
    {
        a++;
    }
}
cout<<a;
return 0;
}

Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, m,	z = 0, k, n;
	cin >> n >> m;
	string s[n];

	ll cx, cy, dx, dy;
	cin >> cx >> cy >> dx >> dy;
	cx--, cy--, dx--, dy--;

	ll dp[n][m];

	rep(i, 0, n, 1) {
		cin >> s[i];
		rep(j, 0, m, 1)	dp[i][j] = hell;
	}


	priority_queue<pair<ll, pll>> q;
	q.push(mp(0, mp(cx, cy)));

	if (s[cx][cy] != '.')	return cout << -1, 0;

	dp[cx][cy] = 0;

	ll x_mo[] = {1, 0, -1, 0};
	ll y_mo[] = {0, 1, 0, -1};

	while (q.size()) {
		pair<ll, pll> temp = q.top();
		q.pop();
		x = temp.ss.ff, y = temp.ss.ss;
		if (temp.ff != -dp[x][y])	continue;

		for (i = 0; i < 4; i++) {
			ll newX = x + x_mo[i];
			ll newY = y + y_mo[i];

			if (newX<n and newX >= 0 and newY >= 0 and newY < m) {
				if (s[newX][newY] == '.' and dp[x][y] < dp[newX][newY] ) {
					dp[newX][newY] = min(dp[x][y], dp[newX][newY]);
					// q.push({newX, newY});
					q.push(mp(-dp[newX][newY], mp(newX, newY)));

				}
			}
		}

		for (i = -2; i <= 2; i++) {
			for (j = -2; j <= 2; j++) {
				ll newX = x + i;
				ll newY = y + j;

				if (newX<n and newX >= 0 and newY >= 0 and newY < m) {
					if (s[newX][newY] == '.' and dp[x][y] + 1 < dp[newX][newY] ) {
						dp[newX][newY] = min(dp[x][y] + 1, dp[newX][newY]);
						// q.push({newX, newY});
						q.push(mp(-dp[newX][newY], mp(newX, newY)));
					}
				}
			}
		}
	}

	z = dp[dx][dy];

	if (z == hell)	z = -1;
	ce(z);
	debug(z);
}



Measured memory_bytes: 12736
#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long                   
#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 
#define o cout<<"BUG"<<endl;
#define IOS ios_base::sync_with_stdio(0);

using namespace std;                    

const ll maxn=2e5+123,inf=1e18,mod=1e9+7,N=360360;
ll n,ans;
string s1,s2,s;
bool used[20];
map< pair< pair<ll,ll> , pair<ll,ll> > , ll>cnt;
pair<ll,ll> base=mp(47,53);
void rec(string &s,int i,bool flag){
    if(i==s.size()){
        pair<ll,ll> h1,h2;
        h1=h2=mp(0,0);
        for(int i=0;i<s.size();i++){
            if(used[i])                                                  
                h1=mp( (h1.f*base.f+s[i])%mod , (h1.s*base.s+s[i])%mod); 
            else
                h2=mp( (h2.f*base.f+s[i])%mod , (h2.s*base.s+s[i])%mod);   
        }
        if(flag)
            ans+=cnt[mp(h1,h2)];
        else
            cnt[mp(h1,h2)]++;
        return;
    }               
    used[i]=0;
    rec(s,i+1,flag);
    used[i]=1;
    rec(s,i+1,flag);
}
int main(){
    #ifdef LOCAL
        freopen ("test.in", "r", stdin);
    #endif
    cin>>n;
    cin>>s;
    s1=s.substr(0,n);
    s2=s.substr(n,n);
    for(int i=0;i<n-i;i++)
        swap(s2[i],s2[n-i-1]);
    rec(s1,0,0);
    rec(s2,0,1);
    cout<<ans;
}


Measured memory_bytes: 41216
/* ABC074_A
    Stuart_yg */
 
#include <stdio.h>
#include <string.h>
#include <math.h>
 
int main(){
    int n,a;
 
    //入力受け取り
    scanf("%d", &n);
    scanf("%d", &a);
    //差を出力
    printf("%d\n",n*n-a);
    return 0;
}

Measured memory_bytes: 128
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

vector<pair<int,int> > a1[110000];
vector<pair<int,int> > a2[110000];

priority_queue<pair<_int64,_int64> > pq;

_int64 shortest1[110000];
_int64 shortest2[110000];
int used[110000];

int main()
{
  int i,j,m,n,s,t,x,y,z,w;
  _int64 ans,tmp1;
  vector<_int64> ret;
  scanf("%d%d%d%d",&n,&m,&s,&t);
  s--;t--;
  for (i=0;i<n;i++)
  {
    a1[i].clear();
    a2[i].clear();
  }
  for (i=0;i<m;i++)
  {
    scanf("%d%d%d%d",&x,&y,&z,&w);
    x--;y--;
    a1[x].push_back(make_pair(y,z));
    a1[y].push_back(make_pair(x,z));

    a2[x].push_back(make_pair(y,w));
    a2[y].push_back(make_pair(x,w));
  }

  while (!pq.empty()) pq.pop();
  for (i=0;i<n;i++)
    shortest1[i]=(1LL<<60);
  shortest1[s]=0;
  pq.push(make_pair(0,s));
  memset(used,0,sizeof(used));
  while (!pq.empty())
  {
    pair<_int64,_int64> tmp=pq.top();
    pq.pop();
    x=tmp.second;
    tmp1=-tmp.first;
    if (used[x]==1) continue;
    used[x]=1;
    for (i=0;i<a1[x].size();i++)
    {
      y=a1[x][i].first;
      if (tmp1+a1[x][i].second<shortest1[y])
      {
        shortest1[y]=tmp1+a1[x][i].second;
        pq.push(make_pair(-shortest1[y],y));
      }
    }
  }

  while (!pq.empty()) pq.pop();
  for (i=0;i<n;i++)
    shortest2[i]=(1LL<<60);
  shortest2[t]=0;
  pq.push(make_pair(0,t));
  memset(used,0,sizeof(used));
  while (!pq.empty())
  {
    pair<_int64,_int64> tmp=pq.top();
    pq.pop();
    x=tmp.second;
    tmp1=-tmp.first;
    if (used[x]==1) continue;
    used[x]=1;
    for (i=0;i<a2[x].size();i++)
    {
      y=a2[x][i].first;
      if (tmp1+a2[x][i].second<shortest2[y])
      {
        shortest2[y]=tmp1+a2[x][i].second;
        pq.push(make_pair(-shortest2[y],y));
      }
    }
  }

  ans=(1LL<<60);
  ret.clear();
  for (i=n-1;i>=0;i--)
  {
    if (shortest1[i]+shortest2[i]<ans) ans=shortest1[i]+shortest2[i];
    ret.push_back(1000000000000000LL-ans);
  }
  reverse(ret.begin(),ret.end());
  for (i=0;i<ret.size();i++)
  {
    printf("%lld\n",ret[i]);
  }
  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int c = a + b;
    if(c == 3) cout << 3 << '\n';
    else if(c == 4) cout << 2 << '\n';
    else cout << 1 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define NUM 10

int cmp(const void *lhs, const void *rhs) {
    return *(int*)rhs - *(int*)lhs;
}

int main(){
    int a[NUM];
    int i;
    char buf[256];
    for ( i =0; i < NUM; ++i ) {
        fgets(buf, sizeof(buf), stdin);
        a[i] = atoi(buf);
    }

    qsort(a, NUM, sizeof(int), cmp);

    for ( i = 0; i < 3; ++i ) {
        printf("%d\n", a[i]);
    }
    return 0;
}

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

int main(void) {
  int A,B;
  cin >> A >> B;
  if((A+B) % 2 == 0) {
    cout << (A+B) / 2 << endl;
  }else if((A+B)%2 == 1) {
    cout << "IMPOSSIBLE " << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int nextInt(){int a;cin>>a;return a;}

int main(){

  int n;
  while(cin>>n,n){
    vector<pair<double,string>> s(n);
    
    REP(i,n){
      cin >> s[i].second;
      int val = nextInt();
      int first_cost = nextInt() + nextInt() + nextInt();
      int end_cost = nextInt() + nextInt();
      int end_val = nextInt()*nextInt();
      int num = nextInt();
      s[i].first =100000000 -  (double)(end_val * num - val) / (end_cost * num + first_cost);
    }
    sort(s.begin(),s.end());
    REP(i,n)
      cout << s[i].second << endl;
    cout << "#" << endl;
  }

  return 0;
}

  

Measured memory_bytes: 3092
#include<stdio.h>
int main()
{
    int a[3][3],sum=0,sum1,sum2,i,j;
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
            sum+=a[i][j];
        }
    sum1=a[0][0]+a[2][1]+a[1][2];
    sum2=a[2][2]+a[0][1]+a[1][0];
    if(a[0][0]+a[2][2]==a[0][2]+a[2][0]&&sum1==sum2&&sum==sum2*3)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();

        int cnt = 0;
        
        for (int i = 0; i < s.length(); i++) {
            if (String.valueOf(s.charAt(i)).equals("1")) {
                cnt++;
            }
        }
        
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  ll n,m,x;cin>>n>>m>>x;
  ll c[n];
  ll a[n][m];
  rep(i,n){
    cin>>c[i];
    rep(j,m){
      cin>>a[i][j];
    }
  }
  ll ans=INF;
  for (int bit = 0; bit < (1<<n); ++bit){
    vector<ll> v(m,0);
    ll now=0;
    for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)){
              now+=c[i];
              rep(j,m){
                v[j]+=a[i][j];
              }
            }
    }
    int ch=0;
    rep(i,m){
      if(v[i]<x){
        ch++;
        break;
      }
    }
    if(ch==0){
      ans=min(ans,now);
    }
  }
  
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
}
                




Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
long long a[N] , b[N];
long long ans;
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%lld %lld" , a + i , b + i);
	}
	for(int i = n ; i >= 1 ; --i){
		a[i] += ans;
		ans += ((a[i] + b[i] - 1LL) / b[i]) * b[i] - a[i];
	}
	printf("%lld\n" , ans);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;




//ここから編集する


int main() {
    string s;
    cin >> s;
    int ans = 0;
    char now = 'a';
    REP(i,0,s.size()){
        if(now != s[i]){
            now = s[i];
            ++ans;
        }
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
string s;cin>>s;
if(s=="ARC")cout<<"ABC"<<endl;
else cout<<"ARC"<<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

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

  V<int> b(n);
  for (int i = n - 1; i >= 0; i--) {
    int s = 0;
    for (int j = i; j < n; j += i + 1) s += b[j];
    if (s % 2 != a[i]) b[i] += 1;
  }
  int m = 0;
  rep(i, n) if (b[i] > 0) m++;
  cout << m << endl;
  rep(i, n) if (b[i] > 0) cout << i + 1 << endl;
}


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

int dp[32769][4];

int main() {
    for(int i=1; i*i <= 32768; ++i) {
        for(int j=0; j<3; ++j) {
            int l = i*i;
            if(j==0) {
                dp[l][j] = 1;
            }
            for(int k=1; k<=32768; ++k) {
                if(k+l <= 32768) {
                    dp[k+l][j+1] += dp[k][j];
                }
            }
        }
    }

    int n;
    while(cin >> n, n) {
        cout << accumulate(begin(dp[n]), end(dp[n]), 0) << endl;
    }
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    for(i = 0;i < n;++i){
        ll a;
        cin >> a;
        if(a%2){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
	int x;
	int h, m, s;
	
	scanf("%d", &x);
	
	h = x / 3600;
	m = x % 3600 / 60;
	s = x % 3600 % 60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s, t, u;
  int A, B;
  cin >> s >> t >> A >> B >> u;

  if(s == u) A--;
  else B--;
  cout << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
        "fmt"
        "sort"
)

func solution(n, m int, matrix [][2]int) int {
        sort.SliceStable(matrix, func(i, j int) bool {
                if matrix[i][0] == matrix[j][0] {
                        return matrix[i][1] > matrix[j][1]
                }
                return matrix[i][0] < matrix[j][0]
        })

        out := 0
        for i := range matrix {
                if m >= matrix[i][1] {
                        m -= matrix[i][1]
                        out += matrix[i][0] * matrix[i][1]
                } else {
                        out += matrix[i][0] * m
                        m = 0
                }
                if m <= 0 {
                        break
                }
        }
        return out
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        matrix := make([][2]int, n)
        for i := 0; i < n; i++ {
                fmt.Scan(&matrix[i][0], &matrix[i][1])
        }
        fmt.Println(solution(n, m, matrix))
}

Measured memory_bytes: 6332
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

// #include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

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

    int k,n; cin>>k>>n; cin.ignore();

    int a1; int prev;
    cin>>a1;
    prev=a1;
    int maxdiff = 0;
    int acurr;
    for (int i=2; i<=n; ++i) {
        cin>>acurr;
        maxdiff = max(maxdiff,acurr-prev);
        prev=acurr;
    }

    //at the end, we have acurr = an; compare this with a1+k-an;
    maxdiff = max(maxdiff,a1+k-acurr);

    cout<<k-maxdiff<<el;

}

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

int main()
{
	string predictions;
	string reality;
	cin >> predictions;
	cin >> reality;
	int c = 0;
	for (int i = 0; i < predictions.length(); i++)
	{
		if (predictions[i] == reality[i]) c++;
	}
	cout << c << endl;


	return 0;
}


Measured memory_bytes: 256
K = int(input())

num_list = [1,9,30,76,141,267,400,624,
885,1249,1590,2208,2689,3411,4248,5248,6081,7485,8530,10248,11889,13687,15228,17988,20053,22569,
25242,28588,31053,35463,38284,42540,46581,50893,55362,61824,65857,71247,76884,84388,89349,97881,
103342,111528,120141,128047,134580,146316,154177,164817,174438,185836,194157,207927,218812,233268,
245277,257857,268182,288216,299257,313635,330204,347836,362973,383709,397042,416448,434025,456967,
471948,499740,515581,536073,559758,583960,604833,633651,652216,683712,709065,734233,754734,793188,
818917,846603,874512,909496,933081,977145,1006126,1041504,1073385,1106467,1138536,1187112,1215145,
1255101,1295142,1342852,1373253,1422195,1453816,1502376,1553361,1595437,1629570,
 1691292,
 1726717,
 1782111,
 1827492,
 1887772,
 1925853,
 1986837,
 2033674,
 2089776,
 2145333,
 2197483,
 2246640,
 2332104,
 2379085,
 2434833,
 2490534,
 2554600,
 2609625,
 2693919,
 2742052,
 2813988,
 2875245,
 2952085,
 3003306,
 3096024,
 3157249,
 3224511,
 3306240,
 3388576,
 3444609,
 3533637,
 3591322,
 3693924,
 3767085,
 3842623,
 3912324,
 4027884,
 4102093,4181949,4270422,4361548,4427853,
4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,
5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,
7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,
9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]

print(num_list[K-1])

Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n;
    cin>>n;
    vector<int> a;
    rep(i,n){
        int tmp;
        cin>>tmp;
        a.push_back(tmp);
    }
    vector<int> ans;
    //ansに詰める順番はaの最後尾から一個飛ばしで先頭まで集める⇒先頭まで来たら折り返して末尾の一個前まであつｍる
    for(int i=n-1;i>=0;i=i-2){
        ans.push_back(a[i]);
    }
    //nが偶数なら折り返しは先頭の要素から,奇数なら2個目から
    for(int i=n%2;i<n;i=i+2){
        ans.push_back(a[i]);
    }

    //出力
    rep(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5580
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=40005;

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

	int n,a,b;
	cin>>n>>a>>b;
	int ans=a*((n)/(a+b));
	// cout<<ans;
	ans+=min(n-(n/(a+b))*(a+b),a);
	cout<<ans;
}
// 
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a,b,d,r;
    double f;
    
    cin>>a>>b;
    
    d=a/b;
    r=a%b;
    f=(double)a/b;
    
    printf("%d %d %f\n",d,r,f);
    //cout<<d<<" "<<r<<" "<<f<<endl;
}


Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>


int main()
{
std::string a;
	std::cin >> a;
	if (a == "abc" || a == "bac" || a == "acb"||a=="bca"||a=="cab"||a=="cba") { std::cout << "Yes" << std::endl; }
	else {
		std::cout << "No" << std::endl;
	}
}

Measured memory_bytes: 256
def b_exactly_n_points(N):
    tmp = 0
    k = 1
    while tmp < N:
        tmp += k
        k += 1
    ans = list(range(1, k))
    if tmp - N > 0:
        ans.remove(tmp - N)
    ans = '\n'.join(map(str, ans))
    return ans

N = int(input())
print(b_exactly_n_points(N))

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

int f(int n) {
    if (n % 2 == 0) return n / 2;
    else return 3 * n + 1;
}

int main() {
    int s;
    cin >> s;
    // int n = 1e6+1;
    // vector<int> a(n);
    int prev = s;
    set<int> m;
    m.insert(s);
    for (int i = 2; ; i++) {
        prev = f(prev);
        if (m.count(prev)) {
            cout << i << "\n";
            break;
        } else {
            m.insert(prev);
        }
    }
    // for (int i = 1; i <= n; i++) {
    //     if (i == 1) {
    //         a[i] = s;
    //     } else {
    //         a[i] = f(a[i-1]);
    //         for (int j = 1; j < i; j++) {
    //             if (a[j] == a[i]) {
    //                 cout << i << endl;
    //                 goto out;
    //             }
    //         }
    //     }
    // }
    // out:
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <iterator>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> pi;

int N;
vector<int> A;
vector<pi> res;

void solve_all_pos(int x, int id) {
	for (int i = 0; i < N; ++i) {
		if (A[i] < 0)
			res.push_back(make_pair(id, i));
	}
	for (int i = 1; i < N; ++i)
		res.push_back(make_pair(i - 1, i));
}

void solve_all_neg(int x, int id) {
	for (int i = 0; i < N; ++i) {
		if (A[i] > 0)
			res.push_back(make_pair(id, i));
	}
	for (int i = N - 2; i >= 0; --i)
		res.push_back(make_pair(i + 1, i));
}

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

	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	
	vector<int>::iterator max_it, min_it;
	max_it = max_element(A.begin(), A.end());
	int max_val = *max_it;
	int max_idx = distance(A.begin(), max_it);
	min_it = min_element(A.begin(), A.end());
	int min_val = *min_it;
	int min_idx = distance(A.begin(), min_it);
	
	if (max_val != min_val) {
		if (max_val + min_val >= 0)
			solve_all_pos(max_val, max_idx);
		else
			solve_all_neg(min_val, min_idx);
	}

	int sz = res.size();
	cout << sz << '\n';
	for (int i = 0; i < sz; ++i)
		cout << res[i].first + 1 << ' ' << res[i].second + 1 << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;
ll dp[300005],dp1[300005];
pll a[300005];
int main()
{
    int n;
    cin>>n;
    ll ans=0;
    set<pll> s,s1;
    for(int i=1;i<=3*n;i++)
    {
        cin>>a[i].FF;
        a[i].SS=i;
    }
    for(int i=1;i<=n;i++){s.insert(a[i]);ans+=a[i].FF;}
    dp[n]=ans;
    for(int i=n+1;i<=2*n;i++)
    {
        if(s.begin()->FF<a[i].FF)
        {
            ans=ans-s.begin()->FF+a[i].FF;
            s.erase(s.begin());
            s.insert(a[i]);
        }
        dp[i]=ans;
    }
    ans=0;
    for(int i=3*n;i>=2*n+1;i--)
    {
        s1.insert(mp(-a[i].FF,a[i].SS));
        ans+=a[i].FF;
    }
    dp1[2*n+1]=ans;
    for(int i=2*n;i>=n+1;i--)
    {
        ll h=-s1.begin()->FF;
        if(a[i].FF<h)
        {
            s1.erase(s1.begin());
            s1.insert(mp(-a[i].FF,i));
            ans=ans-h+a[i].FF;
        }
        dp1[i]=ans;
    }
    ans=-10000000000000000;
    for(int i=n;i<=2*n;i++)
    {
        ans=max(ans,dp[i]-dp1[i+1]);
       // cout<<dp[i]<<" "<<dp1[i+1]<<" "<<i<<endl;
    }
    cout<<ans<<endl;





}




Measured memory_bytes: 21504
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = min(b / a, c);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
x, y = map(int,input().split())
kame = (y - 2*x) / 2
tsuru = x - kame
if kame.is_integer() and tsuru.is_integer():
  if kame > 0 and tsuru >= 0:
    print('Yes')
  elif tsuru > 0 and kame >= 0:
    print('Yes')
  else:
    print('No')
  exit()
else:
  print('No')

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int n,count=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=1;i<n-1;i++)
	{
		if((a[i-1]>a[i]&&a[i]>a[i+1])||(a[i-1]<a[i]&&a[i]<a[i+1]))
		count++;
	}
	cout<<count;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("");
    
    let answer = 1;
    let previous = S[0];
    
    let set = new Set(S);
    
    if([...set].length === 1) {
        console.log(1);
        return;
    }
    
    if([...set].length === N) {
        console.log(N);
        return;
    }
    
    for(let i=1; i<N; i++) {
        // console.log(S[i]);
        // console.log(previous);
        
        if(S[i] !== previous) {
            answer++;
        }
        
        previous = S[i];
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 28972
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,l,la=2,lb=1;
    cin>>n;
    if(n==1) cout<<lb;
    else {
        for(ll i=0;i<n-1;i++){
            l=la+lb;
            la=lb;
            lb=l;
        }
        cout<<l;
    }
}

Measured memory_bytes: 3532