akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

	public void solve() {
		int N = in.nextInt();
		int cnt = 1;
		int before = -1;
		int trend = 0;
		for (int i = 0; i < N; i++) {
			int now = in.nextInt();
			switch (trend) {
			case -1:
				if (now > before) {
					cnt++;
					before = now;
					trend = 0;
				} else {
					before = now;
				}
				break;
			case 1:
				if (now < before) {
					cnt++;
					before = now;
					trend = 0;
				} else {
					before = now;
				}
				break;
			case 0:
				if (before == -1) {
					before = now;
				} else {
					if (before > now) {
						before = now;
						trend = -1;
					} else if (before < now) {
						before = now;
						trend = 1;
					}
				}
				break;
			}
			//out("before=%d, now=%d, trend=%d, cnt=%d\n", before, now, trend,cnt);
		}
		out("%d\n", cnt);
	}

	public void out(String format, Object... s) {
		System.out.printf(format, s);
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}


Measured memory_bytes: 48640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;

  vector<vector<ll>> cnt(10, vector<ll>(10, 0));

  FOR(i, 1, n + 1) {
    string s = to_string(i);
    cnt[s[0] - '0'][s[SZ(s) - 1] - '0']++;
  }

  ll ans = 0;
  FOR(i, 1, 10) FOR(j, 1, 10) { ans += cnt[i][j] * cnt[j][i]; }
  cout << ans << endl;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N;
  cin >> N;
  for(int i = 0; i < 999; i++){
    if(N % 111 == 0){
      cout << N <<endl;
      return 0;
    }
    N++;
  }
}


Measured memory_bytes: 3604
fun main(args: Array<String>) {
    val x = readInteger()
    for (i in x..100003) {
        if (i.isPrime()) {
            println(i)
            return
        }
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerArray() = readStringList().map(String::toInt).toIntArray()
fun readLongArray() = readStringList().map(String::toLong).toLongArray()


fun Int.isPrime(): Boolean {
    if (this <= 1) return false

    var i = 2
    while (i * i <= this) {
        if (this % i == 0) return false
        i++
    }

    return true
}


Measured memory_bytes: 31700
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] a = new int[H+2][W+2];
        int[][] b = new int[H+2][W+2];
        boolean[][][] dp = new boolean[H+1][W+1][((H+W)*80)+1];
        for(int i = 0; i<H+2; i++) {
            for(int j = 0; j<W+2; j++) {
                if(i==0||j==0||i==H+1||j==W+1) {
                    a[i][j] = -1;
                    continue;
                }
                a[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i<H+2; i++) {
            for(int j = 0; j<W+2; j++) {
                if(i==0||j==0||i==H+1||j==W+1) {
                    b[i][j] = -1;
                    continue;
                }
                b[i][j] = sc.nextInt();
            }
        }
        for(int i = 1; i<H+1; i++) {
            for(int j = 1; j<W+1; j++) {
                if(i==1 && j ==1) {
                    int ini = Math.abs(a[i][j] - b[i][j]);
                    dp[i][j][ini] = true;
                }
                for(int k = 0; k<((H+W)*80); k++) {
                    if(i==1 && j ==1) {
                        continue;
                    }
                    if(a[i][j-1]>=0 && dp[i][j-1][k] == true) {
                        int plus = k + Math.abs(a[i][j] - b[i][j]);
                        int minus = Math.abs(k - Math.abs(a[i][j] - b[i][j]));
                        dp[i][j][plus] = true;
                        dp[i][j][minus] = true;
                    }
                    if(a[i-1][j]>=0 && dp[i-1][j][k] == true) {
                        int plus = k + Math.abs(a[i][j] - b[i][j]);
                        int minus = Math.abs(k - Math.abs(a[i][j] - b[i][j]));
                        dp[i][j][plus] = true;
                        dp[i][j][minus] = true;
                    }
                }
            }
        }
        for(int k = 0; k<((H+W)*80); k++) {
            if(dp[H][W][k]) {
                System.out.println(k);
                break;
            }
        }
    }
}

Measured memory_bytes: 155596
package main

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

func main() {
	n := readInt()

	fmt.Println(n * (n - 1) / 2)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= b) puts("unsafe");
    else puts("safe");
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int alp = 26;
int D;
vector<long long> c(alp);
vector< vector< long long > > s;

long long sub(vector<int>& last, int x, int d){
    long long res = s[d][x-1];
    for(int j=0;j<alp;j++){
        if(j != x) res -= c[j] * (d-last[j]);
    }
    return res;
}

long long score(vector<int>& t){
    if(t.size() != D) return 0;
    vector< int > last(alp, -1);
    long long res = 0;
    for(int i=0;i<D;i++){
        res += s[i][t[i]-1];
        last[t[i]-1] = i;
        for(int j=0;j<alp;j++){
            res -= c[j] * (i-last[j]);
        }
    }
    return res;
}

void f(vector<int>& t){
    t.assign(D, 0);
    vector< int > last(alp, -1);
    for(int i=0;i<D;i++){
        int mxj = 1;
        long long mx = -1e9;
        for(int j=1;j<=alp;j++){
            long long tmp = sub(last, j, i);
            if(tmp > mx){
                mxj = j;
                mx = tmp;
            }
        }
        t[i] = mxj;
        last[mxj-1] = i;
    }
}

bool print_t(vector<int>& t){
    if(t.size() != D) return false;
    for(int i=0;i<D;i++){
        cout << t[i] << endl;
    }
    return true;
}

int main(void){
    cin >> D;
    for(int i=0;i<alp;i++) cin >> c[i];
    s.assign(D, vector<long long>(alp, 0));
    for(int i=0;i<D;i++){
        for(int j=0;j<alp;j++) cin >> s[i][j];
    }

    vector<int> t;
    f(t);
    print_t(t);
}


Measured memory_bytes: 3288
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {break;}
            if (W > 300 || H < 1){break;}
            for(int i=1;i<=H;i++){
                if(i%2==1){
                    for(int j=1;j<=W;j++){
                        if(j%2==1){
                            System.out.print("#");
                        }else if(j%2==0){
                            System.out.print(".");
                        }
                    }
                    System.out.println();

                }else if(i%2==0){
                    for(int j=1;j<=W;j++){
                        if(j%2==1){
                            System.out.print(".");
                        }else if(j%2==0){
                            System.out.print("#");
                        }
                    }
                    System.out.println();

                }
            }
            System.out.println();
        }
    }
}


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

int main()
{
  char c;
  cin >> c;

  if (c >= 'A' && c <= 'Z') {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[k+1]={0};
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0)
            {
                if(dp[i-a[j]]==0)
                    {
                        dp[i]=1;
                        break;
                    }
            }
        }
    }
    if(dp[k]==1)
     cout<<"First";
    else
     cout<<"Second";
}



Measured memory_bytes: 1024
s = list(input())
words = ["dream", "dreamer", "erase", "eraser"]
ans = True
while True:
    if s == []:
        print("YES")
        break
    if "".join(s[-5:]) == "dream":
        del s[-5:]
    elif "".join(s[-7:]) == "dreamer":
        del s[-7:]
    elif "".join(s[-5:]) == "erase":
        del s[-5:]
    elif "".join(s[-6:]) == "eraser":
        del s[-6:]
    else:
        print("NO")
        break




Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)>>1)
using namespace std;
int n,m;
struct node{
	int next,to;
}a[1500005];
int head[500005],cnt,v[500005],p[500005],minn[2000005],da[500005];
void add(int e,int r){
	a[++cnt].next=head[e];a[cnt].to=r;head[e]=cnt;
}
priority_queue<int>q;
inline int read(){
	char c=getchar();int s=0;
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		s=s*10+c-'0';c=getchar();
	}return s;
}
inline void update(int u){
	if(v[minn[ls]]>v[minn[rs]])minn[u]=minn[ls];
	else minn[u]=minn[rs];
}
void build(int u,int l,int r){
	if(l==r){return (void)(minn[u]=l);}
	build(ls,l,mid);
	build(rs,mid+1,r);
	update(u);
}
void add(int u,int l,int r,int x){
	if(l==r){return (void)(minn[u]=0);}
	if(x<=mid)add(ls,l,mid,x);
	else add(rs,mid+1,r,x);
	update(u);
}
int query(int u,int l,int r,int L,int R){
	if(L>R)return 0;
	if(L<=l&&R>=r){return minn[u];}
	int jly=0;
	int jlx=0;
	if(L<=mid)jlx=query(ls,l,mid,L,R);
	if(R>mid)jly=query(rs,mid+1,r,L,R);
	if(v[jlx]>v[jly])return jlx;
	else return jly;
}
int bj[500005];
void pd(int u){
	if(bj[u])return ;
	if(query(1,1,n,max(1,u-m+1),min(u+m-1,n))==u)return (void)(q.push(u),bj[u]=1);
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++)v[i]=read();
	build(1,1,n);minn[0]=-19191981;bj[0]=1;
	for(int i=n;i>=1;i--){
		pd(i);
	}
	for(int i=n;i>=1;i--){
		int u=q.top();
		q.pop();
		add(1,1,n,u);
		da[u]=i;
		int x=query(1,1,n,max(1,u-m+1),u-1);
		pd(x);
		int y=query(1,1,n,u+1,min(u+m-1,n));
		pd(y);
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",da[i]);
	}
}

Measured memory_bytes: 15900
import sys


sys.setrecursionlimit(10 ** 6)


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 roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


def main():
    N, M = list(map(int, input().split()))
    tree = UnionFind(N)
    for _ in range(M):
        A, B = list(map(int, input().split()))
        A -= 1
        B -= 1
        tree.union(A, B)
    ans = 1
    for n in range(N):
        ans = max(ans, tree.size(n))
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  ll N,M;
  cin >> N >> M;
  vector<pair<ll,ll>> a;
  for(ll i=0;i<N;i++){
    ll x;
    cin >> x;
    a.push_back( make_pair(x,1) );
  }
  for(ll i=0;i<M;i++){
    ll b,c;
    cin >> b >> c;
    a.push_back( make_pair(c,b) );
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  ll cnt=0;
  vector<ll> res;
  for(auto p : a){
    ll b,c;
    tie(b,c) = p;
    for(int i=0;i<c;i++){
      res.push_back(b);
    }
    if(res.size() >= N){
      break;
    }
  }
  
  ll sum=0;
  for(ll i=0;i<N;i++){
    sum += res.at(i);
  }
  
  cout << sum << endl;
  
  return(0);
}

Measured memory_bytes: 9360
#include <deque>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[] = {1, 0, -1, 0};

int main(int argc, char *argv[])
{
  int n,q,time;
  ll cnt_t=0;
  string name;
  deque<pair<string, int>> dq;
  pair<string, int> c;
  cin>>n>>q;
  rep(i,n){
    cin>>name>>time;
    dq.emplace_back(name,time);
  }
  while(!dq.empty()){
    c = dq.front();
    dq.pop_front();
    cnt_t+=min(c.second,q);
    c.second-=q;
    if(c.second>0) {
      dq.push_back(c);
    } else {
      cout<<c.first<<" "<<cnt_t<<endl;
    }

  }
  return 0;
}



Measured memory_bytes: 6188
# coding: utf-8
N = int(input())
l = [[0 for _ in range(10)] for _ in range(10)]
for v in range(1, N+1):
    a, b = int(str(v)[0]), int(str(v)[-1])
    l[a][b] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += l[i][j] * l[j][i]
print(ans)

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main () {
	int n = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri() / 10;
	
	int max = 0;
	for (int i = 0; i < n; i++) {
		if (i > max) break;
		max = std::max(max, i + a[i]);
	}
	if (max < n - 1) {
		std::cout << "no" << std::endl;
		return 0;
	}
	int min = n - 1;
	for (int i = n - 1; i >= 0; i--) {
		if (i < min) break;
		min = std::min(min, i - a[i]);
	}
	std::cout << (min <= 0 ? "yes" : "no") << std::endl;
	return 0;
}



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

ll score = 0;
int N = 26;
int D;

vector<int> c(N+1);
vector<vector<int>> s;
vector<int> t;
vector<int> last(N+1, 0);

void greedy(){
    for(int d = 1; d <= D; d++){
        ll max_score = -1e9;
        vector<int> max_last;
        for(int n = 1; n <= N; n++){
            ll tmp_score = 0;
            vector<int> tmp_last(N+1);
            tmp_last = last;
            
            tmp_score +=  s[d][n];
            tmp_last[n] = d;
     
            int penalty = 0;
            for(int i = 1; i <= N; i++){
                penalty += c[i]*(d-tmp_last[i]);    
                
            }
            
            tmp_score -= penalty;

            if(max_score < tmp_score){
                max_score = tmp_score;
                max_last = tmp_last;
                t[d] = n;
            }                    
            
        }
        
        last = max_last;
        
    }    
}


int main(){
    cin>> D;

    s.resize(D+1);
    for(int i=0; i<=D; i++){
        s[i].resize(N+1);
    }
    t.resize(D+1);
    for(int i=1; i<=N; i++){
        cin>>c[i];
    }

    for(int i=1; i<=D; i++){
        for(int j=1; j<=N; j++){
            cin>>s[i][j];
        }
    }

    greedy();

   
    for(int i=1; i<=D; i++){           
        cout<<t[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
void setIO(string name) {
  freopen((name+".in").c_str(),"r",stdin);
  freopen((name+".out").c_str(),"w",stdout);
}
vector<int> adj[200005];
int visited[200005]={0};
int ender=-1;

vector<int> c;
void dfs(int node,int length){
  visited[node]=length;
   c.pb(node);
  for(int next:adj[node]){
    if(!visited[next]){
      
      dfs(next,length+1);

    }else{
      ender=next;
    }
  }
 
}

int main() {
   fast();
   //setIO("moop");
   int n;
   cin>>n;
   long long k;
   cin>>k;
   for(int i=0;i<n;i++){
    int l;
    cin>>l;
    --l;
    adj[i].pb(l);
   }
   dfs(0,1);
   int length_of_cycle;
   if(ender!=-1){
     int x;
      for(int i=0;i<c.size();i++){
        if(c[i]==ender){
           x=i;
           break;
        }
      }
     if(k<=x){
       cout<<c[k]+1<<"\n";
       return 0;
     }else{
      long long y=c.size()-x;
      k-=x;
      k%=y;
      cout<<c[k+x]+1<<"\n";
      return 0;
     }
      
   }

   

   

   
   



   
}
 

Measured memory_bytes: 28048
import math

n, m = map(int, input().split(" "))

ans = list([0 for _ in range(n)])

err = False
for i in range(m):
    s, c = map(int, input().split(" "))
    if s == 1 and c == 0:
        if n == 1:
            print(0)
            exit()
        err = True
    elif ans[s - 1] == 0:
        ans[s - 1] = c
    elif not ans[s - 1] == c:
        err = True

if ans[0] == 0:
    ans[0] = 1

if (n == 1 and ans[0] == 0) or (n == 1 and m == 0):
    print(0)
    exit()

if err:
    print(-1)
    exit()

print("".join(map(str, ans)))

Measured memory_bytes: 3064
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    int n;
    cin >> n;
    int ans = (int)sqrt(n);
    cout << ans * ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	sort (s.begin(),s.end());
	cout<<(s=="abc"?"Yes":"No")<<endl;
	return 0;
}

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

					using namespace std;
					typedef long long ll;

					int main()
					{
						string s;
						cin >> s;
						if(s[0] == '7' || s[1] == '7' || s[2] == '7')
							cout << "Yes";
						else cout << "No";	
					}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
	int n, m, i, j, k, l;
	long long int s;
	int A[100][100], B[100][100];
	
	scanf("%d%d%d", &n, &m, &l);
	
	/*Aの配列*/
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d", &A[i][j]);
		}
	}
	/*bの配列*/
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d", &B[i][j]);
		}
	}
	/*cの配列*/
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			s = 0;
			for(k=0;k<m;k++){
				s += A[i][k]*B[k][j];
			}
			if(j>0){
				printf(" ");
			}printf("%lld", s);
		}printf("\n");
	}
return 0;
}


Measured memory_bytes: 2048
from fractions import gcd
from functools import reduce

n = int(input())

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

t = set()
for _ in range(n):
    t.add(int(input()))

print(lcm_list(t))

Measured memory_bytes: 5076
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
struct dog {
	string a;
	int b;
};
int main()
{
	//int h, a;
	//cin >> h >> a;
	//int ans;
	//ans = h / a;
	//if (h - ans*a == 0) {}
	//else { ans += 1; }
	//cout << ans;

	int h, n;
	cin >> h >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		h -= a;
		if (h <= 0) { cout << "Yes"; exit(0); }
	}
	cout << "No";
}



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

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

    if(a == b && b != c) cout << "Yes" << endl;
    else if(b == c && c != a) cout << "Yes" << endl;
    else if(c == a && a != b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int gcd(int x, int y){
    if(x<y)swap(x,y);
    if(y==0)return x;
    return gcd(x%y,y);
}

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];
  vector<int> L(N);//A[0]~A[i]の最大公約数
  vector<int> R(N);//A[i]~A[N-1]の最大公約数
  L[0]=A[0];
  R[N-1]=A[N-1];
  
  for(int i=1;i<=N-1;i++) L[i]=gcd(L[i-1],A[i]);
  for(int i=N-2;i>=0;i--) R[i]=gcd(R[i+1],A[i]);
  
  int mx=max(L[N-2],R[1]);//両端を抜いた場合
  for(int i=1;i<=N-2;i++){//両端以外を抜いた場合
    mx = max(mx, gcd(L[i-1],R[i+1]));
  }
  cout<<mx<<endl;
  return 0;
}

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

int main()
{
  int i,j,k,h,w,a,b;
  int map[61][61],color[61][61],d[61][61];
  queue<pair<int,int> > Q;
  pair<int,int> u;
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    for(i=0;i<h*2+1;i++){
      for(j=0;j<w*2+1;j++){
        color[i][j]=0;d[i][j]=200;
        if(i==0||j==0||i==h*2||j==w*2){
          map[i][j]=1;
	}
        else if(i%2==1 &&j%2==0){
          cin>>map[i][j];
	}
	else if(i%2==0 &&j%2==1){
          cin>>map[i][j];
	}
        else map[i][j]=0;
      }
    }
    d[1][1]=1;color[1][1]=1;
    Q.push(make_pair(1,1));
    while(!Q.empty()){
      u=Q.front();Q.pop();
      a=u.first;b=u.second;
      if(map[a+1][b]==0 && color[a+2][b]==0){
	d[a+2][b]=d[a][b]+1;
	color[a+2][b]=1;
	Q.push(make_pair(a+2,b));
      }
      if(map[a][b+1]==0 && color[a][b+2]==0){
	d[a][b+2]=d[a][b]+1;
	color[a][b+2]=1;
	Q.push(make_pair(a,b+2));
      }
      if(map[a-1][b]==0 && color[a-2][b]==0){
	d[a-2][b]=d[a][b]+1;
	color[a-2][b]=1;
	Q.push(make_pair(a-2,b));
      } 
      if(map[a][b-1]==0 && color[a][b-2]==0){
	d[a][b-2]=d[a][b]+1;
	color[a][b-2]=1;
	Q.push(make_pair(a,b-2));
      }
      color[a][b]=2;
    }
    if(d[h*2-1][w*2-1]==200)cout<<0<<endl;
    else cout<<d[h*2-1][w*2-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
struct info{
  long pos;
  long val;
  bool operator<(const info another){
	return val < another.val;
  }
};
int main(){
  long n,ii;
  vector<info> x;
  vector<int> highLow;
  long mid1,mid2;

  cin >> n;
  x.resize(n);
  highLow.resize(n+1);
  
  for(ii=0;ii<n;ii++){
	x[ii].pos = ii+1;
	cin >> x[ii].val;
  }

  //中央値の候補
  sort(x.begin(),x.end());
  mid1 = n/2;
  mid2 = mid1 + 1;
  long pos;
  for(ii=0;ii<n;ii++){

	pos = x[ii].pos;
	if(ii<mid1-1){
	  highLow[pos] = 0;
	}
	else if(ii==mid1-1){
	  highLow[pos] = 1;
	}
	else if(ii==mid2-1){
	  highLow[pos] = 2;
	}
	else{
	  highLow[pos] = 3;
	}
	//cout << "ii:" << ii << "pos:" << x[ii].pos << "val:" << x[ii].val <<  endl;
  }
  long mid1Val,mid2Val;

  mid1Val = x[mid1-1].val;
  mid2Val = x[mid2-1].val;
  
  for(ii=1;ii<=n;ii++){
	if(highLow[ii] == 0){
	  cout << mid2Val << endl;
	}
	else if(highLow[ii] == 1){
	  cout << mid2Val << endl;
	}

	else if(highLow[ii] == 2){
	  cout << mid1Val << endl;
	}
	else{
	  cout << mid1Val << endl;
	}
	//if(highLow[ii
  }
//  for(ii=1;ii<=mid1;ii++){
//	cout << x[mid1] << endl;
//  }
//
//  for(ii=mid2;ii<=n;ii++){
//	cout << x[mid2] << endl;
//  }
  
  return 0;
}


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

using namespace std;

int mod=1e9+7;

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

    int a,b,c,k;
    cin>>a>>b>>c>>k;

    int MAX=max(a,max(b,c));

    int ans=a+b+c-MAX+MAX*pow(2,k);

    cout<<ans<<endl;

}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll n,a,b;cin>>n>>a>>b;
    vl x(n),d(n);
    rep(i,n)cin>>x[i];
    for(int i=1;i<n;++i){
        d[i]=x[i]-x[i-1];
    }
    ll ans=0;
    for(int i=1;i<n;++i){
        ans+=min(a*d[i],b);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define            bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
     cin >> n >> k;
     set<int > st;
     int ans = 0;

     fo(i,1,k+1)
     {
          cin >> m;

          fo(i,1,m+1)
          {
               int x;
               cin >> x;
               st.insert(x);
          }
     }

     fo(i,1,n+1) ans += ( !st.count(i) );
     cout << ans << endl;
}

int32_t main()
{
     FAST;     
     int t=1; 
     cout << fixed << setprecision(10);
     // cin>>t;
     test(t) go();
}

 

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


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
ll poq(ll x, ll y, ll md)
{
	ll pro = 1;
	while(y)
	{
		if(y%2)
		{
			pro = (pro*x)%md;
		}
		x = (x*x)%md;
		y/=2;
	}
	return pro;
} 
int main()
{
	ios_base::sync_with_stdio(false);
	ll a=0,s=0,i,n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		a = (a + (x*x)%mod)%mod;
		s = (s + x)%mod;
	}
	s = (s*s)%mod;
	ll ans = (s-a+mod)%mod;
	ans = (poq(2, mod-2, mod) * ans)%mod;
	cout<<ans<<nl;
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    int kabu = 0, money = 1000;
    rep(i, 0, n) {
        if (i != n - 1) {
            if (a[i] < a[i + 1]) {
                kabu += money / a[i];
                money %= a[i];
            } else if (a[i] == a[i + 1]) {
                continue;
            } else {
                money += a[i] * kabu;
                kabu = 0;
            }
        } else {
            money += a[i] * kabu;
            kabu = 0;
        }
        // cout << money << " " << kabu << "\n";
    }
    cout << money << "\n";
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int A,P; cin >> A>>P;
    cout << (A*3+P)/2 << endl; 
}


Measured memory_bytes: 256
#include<stdio.h>










int main(){
 int i,j,n,q;
 int count=0;

scanf("%d",&n);
int S[n];
for(i=0;i<n;i++){ scanf("%d",&S[i]);}

scanf("%d",&q);
int T[q];
for(i=0;i<q;i++){ scanf("%d",&T[i]);}


for(i=0;i<q;i++){ 
 for(j=0;j<n;j++){ if(T[i]==S[j]){count++; break;} }}

printf("%d\n",count);

return 0;
} 

Measured memory_bytes: 1860
n, a, b = map( int, input().split() )
sum = 0
count = 1

while count <= n:

    c_check = 0
    count_temp = count
    while 1:
        c_check += count_temp % 10
        count_temp = int(count_temp/10)
        if count_temp<1:
            break

    if a <= c_check and b >= c_check:
        sum += count

    count += 1


print("{}".format(sum))

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;

namespace abc139_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var h = CIn.ReadIntArray(n);

      var ans = 0;
      var count = 0;

      for (var i = 1; i < n; i++)
      {
        if (h[i - 1] >= h[i])
        {
          count++;
        }
        else
        {
          ans = Math.Max(ans, count);
          count = 0;
        }
      }
      ans = Math.Max(ans, count);

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 2 == 1 && a[i] % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: Chars,
    }
    let last = n.last().unwrap();
    match last {
        '0' | '1' | '6' | '8' => println!("pon"),
        '3' => println!("bon"),
        _ => println!("hon"),
    }
}


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

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef double ld;

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

    int N;
    cin >> N;
    vi64 x(N), y(N);
    
    int mod = -1;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    for (int i = 0; i < N; i++) {
        i64 m = abs(x[i] + y[i]) % 2LL;
        if (mod < 0) mod = m;
        else {
            if (mod != m) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    int a = 38;
    if (mod == 0) {
        cout << a + 2 << endl;
    } else {
        cout << a + 1 << endl;
    }

    for (i64 m = a; m >= 0; m--) {
        i64 b = 1;
        b = (b << m);
        cout << b;
        if (m > 0) cout << " ";
    }

    if (mod == 0) cout << " " << 1;

    cout << endl;

    for (int i = 0; i < N; i++) {
        for (int m = a; m >= 0; m--) {

            i64 d = 1;
            d = (d << m);

            if (abs(x[i]) > abs(y[i])) {
                if (x[i] > 0) {
                    x[i] -= d;
                    cout << "R";
                } else {
                    x[i] += d;
                    cout << "L";
                }
            } else {
                if (y[i] > 0) {
                    y[i] -= d;
                    cout << "U";
                } else {
                    y[i] += d;
                    cout << "D";
                }
            }
        }

        if (mod == 0) {
            if (x[i] > 0) {
                cout << "R";
                x[i] -= 1;
            }
            else if (x[i] < 0) {
                cout << "L";
                x[i] += 1;
            }
            else if (y[i] < 0) {
                cout << "D";
                y[i] += 1;
            }
            else if (y[i] > 0) {
                cout << "U";
                y[i] -= 1;
            }
        }

        assert (x[i] == 0);
        assert (y[i] == 0);
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n;
    ll a[n+2];
    ll cnt[100005]={0};
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        cnt[a[i]]++;
    }
    cin>>m;
    while(m-->0){
        ll x,y;
        cin>>x>>y;
        sum+=(y-x)*cnt[x];
        cout<<sum<<endl;
        cnt[y]+=cnt[x];
        cnt[x]=0;
    }
}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  map<int,int> mp;
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    if(mp.count(vec.at(i))){
      mp[vec.at(i)]++;
    }
    else{
      mp[vec.at(i)] = 1;
    }
  }
  sort(vec.rbegin(),vec.rend());
  vector<int64_t> pow2(32);
  for(int i=0; i<32; i++){
    pow2.at(i) = pow(2,i);
  }
  vector<int> need(N);
  for(int i=0; i<N; i++){
    for(int j=0; j<32; j++){
      if(pow2.at(j) > vec.at(i)){
        need.at(i) = pow2.at(j) - vec.at(i);
        break;
      }
    }
  }
  
  int ans = 0;
  map<int,int> already;
  for(int i=0; i<N; i++){
    if(already.count(vec.at(i))){
      if(already[vec.at(i)] > 0){
        already[vec.at(i)]--;
        continue;
      }
    }
    if(mp.count(need.at(i))){
      if((need.at(i) != vec.at(i) && mp[need.at(i)] > 0) || (need.at(i) == vec.at(i) && mp[need.at(i)] > 1)){
        mp[need.at(i)]--;
        mp[vec.at(i)]--;
        ans++;
        if(already.count(need.at(i))){
          already[need.at(i)]++;
        }
        else{
          already[need.at(i)] = 1;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main(){
    int mn=1000000000;
    int mx=1;
    int n;cin>>n;
    for(int i = 0 , a ; i < n ; i ++){
        cin>>a;
        mn=min(mn,a);
        mx=max(mx,a);
    }
    cout<<mx-mn;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
const double E = 1e-7;
const ll INF = 1e17;
#define forn(i, s, f) for (int i = s; i < f; ++i)
#define ft first                                                 
#define sec second
#define fora(i, n) for (auto i : n)
#define sz(a) (int)(a).size()
#define sort_(a) sort(a.begin(), a.end())
#define pb push_back
#define mp make_pair
#define rsort_(a) sort(a.begin(), a.end()); reverse(a.begin(), a.end())
#define fast_ cin.tie(0), ios_base::sync_with_stdio(false)
// ____________________________________________________________
#define cina(a) forn(i,0,sz(a)) cin >> a[i]
#define cinpr(a) cin >> a.ft >> a.sec 
//--------------------------------------------------------------

const int MAXN = 3 * 1e5;

vector<vector<ll> > pref(200, vector<ll> (10, 0)), dp(200, vector<ll> (10, 0));

ll binpow (ll a, ll n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}

ll func(int i, int j, ll k) {
    if (i == 0) {
        return j;
    }
    forn(z, max(j-1, 0), min(j+2, 10)) {
        if (k > dp[i-1][z]) {
            k-=dp[i-1][z];
        } else {
            //  cout << "j * pow: " << j * binpow(10, i) <<  '\n';
            ll ans = func(i-1, z, k);
            return j * binpow(10, i) + ans;
        }
        
    }
    cout << "jopa\n";
        return 0;
}
int main() {
    int k; cin >> k;
    
    forn(i,0,10) dp[0][i] = 1;
    forn(i,1,10) pref[0][i] = pref[0][i-1]+1;
    forn(i,1,200) {
        dp[i][0] = dp[i-1][0] + dp[i-1][1];
        dp[i][9] = dp[i-1][8] + dp[i-1][9];
        pref[i][0] = pref[i-1][9];
        forn(j,1,9) {
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1];
            pref[i][j] = pref[i][j-1] + dp[i][j];
        }
        pref[i][9] = pref[i][8] + dp[i][9];
    }

    
    /*
    forn(i,0,4) {
        forn(j,0,10) {
            cout << dp[i][j] << " ";
        }
        cout << '\n';
    }
    cout << "----------------\n";

    forn(i,0,4) {
        forn(j,0,10) {
            cout << pref[i][j] << " ";
        }
        cout << '\n';
    }
    */

    forn(i,0,200) {
        forn(j,1,10) {
            if (pref[i][j] >= k) {
               ll last = dp[i][j] - (pref[i][j] - k);
                cout << func(i,j, last) << '\n';
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 100000;
int sum[MAXN];
int cnt[11];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    while (cin >> s) {
        if (s == "0") break;
        int n = s.size();
        memset(cnt, 0, sizeof(cnt));
        cnt[0] = 1;
        for (int i = 0; i < n; i++) {
            int num = (s[i]-'0');
            sum[i+1] = sum[i] + (i%2==0 ? num : -num);
            sum[i+1] = (sum[i+1]+11)%11;
            cnt[sum[i+1]]++;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int num = sum[i];
            cnt[num]--;
            if (s[i] != '0') ans += cnt[num];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
n,a,b=gets.split.map(&:to_i)
h=(1..n).map{gets.to_i}
r=(h.max/b)+1
l=1
while l<r
  c=(l+r)/2
  if h.map{|i|[(i-c*b+a-b-1)/(a-b),0].max}.inject(:+) <= c
    r=c
  else
    l=c+1
  end
end
p l


Measured memory_bytes: 17972