akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

/*
    nCk, nPk, 階乗をmodをとりつつ求めるライブラリ
*/
template <int MAX_N = 100000, long long MOD = 1000000007LL>
class Combination {
    array<long long, MAX_N + 1> _fact;
    array<long long, MAX_N + 1> _fact_inv;

public:
    // xの逆元
    // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
    long long inv(long long a) const {
        long long b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);

            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0)
            u += MOD;
        return u;
    }
    // n!
    long long fact(long long n) const {
        return _fact[n];
    }
    // 1 / n!
    long long fact_inv(long long n) const {
        return _fact_inv[n];
    }
    // nPk
    long long perm(long long n, long long k) const {
        return fact(n) * fact_inv(n - k) % MOD;
    }
    // nCk
    long long comb(long long n, long long k) const {
        return perm(n, k) * fact_inv(k) % MOD;
    }

    Combination() : _fact{}, _fact_inv{} {
        _fact[0] = _fact[1] = 1LL;
        for (int i = 2; i <= MAX_N; ++i) {
            _fact[i] = _fact[i - 1] * i % MOD;
        }
        _fact_inv[MAX_N] = inv(_fact[MAX_N]);
        for (int i = MAX_N - 1; i >= 0; --i) {
            _fact_inv[i] = _fact_inv[i + 1] * (i + 1) % MOD;
        }
    }
};

constexpr ll mod = inf;
Combination<200000> cm;

int main() {
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;
    for (ll d = 1; d <= n - 1; ++d) {
        ans += (n - d) * m * m * d;
        ans %= mod;
    }
    for (ll d = 1; d <= m - 1; ++d) {
        ans += (m - d) * n * n * d;
        ans %= mod;
    }
    cout << ans * cm.comb(n * m - 2, k - 2) % mod << endl;
    return 0;
}

Measured memory_bytes: 3328
program Project1;
             
{$APPTYPE CONSOLE}
         
uses
  SysUtils,math;
var
  g,r,a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t,z:Integer;
  //l:array of Integer;
  l,l1,l2:int64;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
  xc,yc,space:char;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(n);
    Read(a);
    Readln(b);

    Writeln(((n*a)+b-abs((n*a)-b))div 2);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  REP(i, n) {
    ll x;
    cin >> x;

    ans += min(x * 2, (k - x) * 2);
  }

  cout << ans << "\n";
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;
    string s, t;


    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> s >> t;
    for(int i = 0; i < max(s.size(), t.size()); ++i){
        if(s.size() != i)
            cout << s[i];
        if(t.size() != i)
            cout << t[i];
    }
    cout << endl;
}


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

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String o = input.readLine();
        String e = input.readLine();

        StringBuilder out = new StringBuilder();

        for (int i = 0; i < Math.max(o.length(), e.length()); i++) {
            if (i < o.length())
                out.append(o.charAt(i));

            if (i < e.length())
                out.append(e.charAt(i));
        }
        System.out.println(out);
    }
}


Measured memory_bytes: 22612
#include <iomanip>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  int k;
  cin >> n >> k;

  double ans = 0.0;
  for (int i = 1; i <= n; i++) {
    if (i >= k) {
      ans += 1.0;
    } else {
      int ii = i;
      int a = 1;
      while (ii < k) {
        ii = (ii << 1);
        a = (a << 1);
      }
      ans += static_cast<double>(1.0 / a);
    }
  }
  cout << setprecision(10) << static_cast<double>(ans / n) << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var n = int.Parse(Console.ReadLine());
    var aho = Console.ReadLine().Split();
    var moto = aho.Length;
    var zen = new List<int>();
    var a = 1;
    for(var i = 0;i<moto;i++){
      var c = int.Parse(aho[i]);
      if(c == a){
        a+=1;
        zen.Add(c);
      }
    }
    if(moto-zen.Count > n||zen.Count == 0) Console.WriteLine("-1");
    else Console.WriteLine(n - zen.Count);
  }
}

Measured memory_bytes: 35420
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		long num = s.nextLong();
		long mul = 1;
		ArrayList<Long> inputs = new ArrayList<>();
		for (int i = 0; i < num; i++) {
			inputs.add(s.nextLong());
		}
		
		Collections.sort(inputs);
					
		if (inputs.get(0) == 0) {
			    System.out.println(0);
			    System.exit(0);
		
		}
		
		for(long l:inputs) {
			
			mul *= l;
			
            if (mul < l) {
    			System.out.println(-1);
    			System.exit(0);
            }	
		}
		

		if (mul > 1000000000000000000L) {
			System.out.println(-1);
		}

		else {
			System.out.println(mul);
		}
		

	}

}


Measured memory_bytes: 61964
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<int> P;

class C{
  public:
    P n;
    char *p;
    C(){}
    C(P nn, char *pp) { n = nn; p = pp; }
    C(int r, int i, char *pp) { n.real(r); n.imag(i); p = pp; }
};

bool f;

void check(P p){
  int r = p.real(), i = p.imag();
  if(r > 10000 || r < -10000 || i > 10000 || i < -10000) f = false;
}

C fact(char *p);
C term(char *p);
C expr(char *p);

int main(){
  string s;
  while(cin >>s){
    f = true;
    char *cs = new char[s.length() + 1];
    strcpy(cs, s.c_str());
    C ans = expr(cs);
    if(f){
      if(ans.n.imag() == 0) cout <<ans.n.real() <<endl;
      else if(ans.n.real() == 0) cout <<ans.n.imag() <<'i' <<endl;
      else cout <<ans.n.real() <<(ans.n.imag() < 0 ? '-' : '+') <<abs(ans.n.imag()) <<'i' <<endl;
    } else cout <<"overflow" <<endl;
  }
  return 0;
}

C fact(char *p){
  if(*p == 'i'){
    return C(0, 1, ++p);
  } else if(isdigit(*p)){
    int t = *(p++) - '0';
    while(isdigit(*p)){
      if(t > 10000) { f = false; return C(t, 0, p); }
      t = t * 10 + *(p++) - '0';
    }
    check(P(t, 0));
    return C(t, 0, p);
  } else if(*p == '('){
    C r = expr(p + 1);
    return C(r.n, r.p + 1);
  } else{
    exit(0);
  }
}


C term(char *p){
  C r = fact(p);
  while(*r.p == '*'){
    char op = *r.p;
    complex<int> tmp = r.n;
    r = fact(r.p + 1);
    check(r.n); check(tmp); check(tmp * r.n);
    r.n = tmp * r.n;
  }
  return r;
}

C expr(char *p){
  C r = term(p);
  while(*r.p == '+' || *r.p == '-'){
    char op = *r.p;
    P tmp = r.n;
    r = term(r.p + 1);
    check(r.n); check(tmp);
    if(op == '+'){
      check(tmp + r.n);
      r.n = tmp + r.n;
    }
    else{
      check(tmp - r.n);
      r.n = tmp - r.n;
    }
  }
  return r;
}

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

int main(){
        string s, s1, s2;
        int soma=0, soma2=0;
        cin >> s;
        s1 = s;
        s2 = s;
        for(int i=s.size()-1; i>=0; i--){
                if(i%2==0){
                        s[i] = '0';
                        s2[i] = '1';
                }
                else{
                        s[i] = '1';
                        s2[i] = '0';
                }
                if(s1[i]!=s[i]){
                        soma+=1;
                }

                if(s1[i]!=s2[i]){
                        soma2+=1;
                }
        }
        if(soma<=soma2){
                cout << soma << endl;
        }
        else{
                cout << soma2 << endl;
        }
        return 0;
}


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

#define PI 3.14159265359

#define INF 999999;

#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/



int V, E;
vector<int> G[10000];
vector<int> rG[10000];
vector<int> vs;
bool used[10000];
int cmp[10000];


void add_edge(int from, int to)
{
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v)
{
	used[v] = true;
	for (int i=0; i<G[v].size(); i++)
	{
		if (!used[G[v][i]]) dfs(G[v][i]);
	}
	vs.push_back(v);
}

void rdfs(int v, int k)
{
	used[v] = true;
	cmp[v] = k;
	for (int i=0; i<rG[v].size(); i++)
	{
		if (!used[rG[v][i]]) rdfs(rG[v][i], k);
	}
}

int main()
{
	cin >> V >> E;
	
	REP(E)
	{
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	
	
	//memset(used, 0, sizeof(used));
	REP(10000) used[i] = false;
	vs.clear();
	for (int v=0; v<V; v++)
	{
		if (!used[v]) dfs(v);
	}
	//memset(used, 0, sizeof(used));
	REP(10000) used[i] = false;
	int k = 0;
	for (int i=vs.size()-1; i>=0; i--)
	{
		if (!used[vs[i]]) rdfs(vs[i], k++);
	}
	
	int Q;
	
	cin >> Q;
	REP(Q)
	{
		int u, v;
		cin >> u >> v;
		if (cmp[u] == cmp[v])
		{
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 2780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    string str;
    int n;
    cin >> n;
    vector<int> vx, vy, vz;
    for(int i = 0; i < n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        vx.push_back(x);
        vy.push_back(y);
        vz.push_back(z);
    }
    
    for(int i = 0; i < n; i++) {
        vector<int> v;
        v.push_back(vx[i]);
        v.push_back(vy[i]);
        v.push_back(vz[i]);

        sort(v.begin(), v.end());
        if(pow(v[2],2.0) == pow(v[0],2.0) + pow(v[1],2.0)){
            str = "YES";
        } else {
            str = "NO";
        }
        cout << str << endl;
    }  
}

Measured memory_bytes: 3116
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        char[] S = in.s(N);
        int r = 0;
        int g = 0;
        int b = 0;
        for (int i = 0; i < N; i++) {
            if (S[i] == 'R') r++;
            else if (S[i] == 'G') g++;
            else b++;
        }
        long ans = (long)r * g * b;
        for (int i = 0; i < N - 2; i++) {
            for (int j = 1; ; j++) {
                int x = i;
                int y = x + j;
                int z = y + j;
                if (z >= N) break;
                if (S[x] != S[y] && S[y] != S[z] && S[z] != S[x]) {
                    ans--;
                }
            }
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32688
n,m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(y) for y in input().split()]
mod = 10**9+7

Xd = []
for i in range(n-1):
    Xd.append(X[i+1]-X[i])
    
Yd = []
for i in range(m-1):
    Yd.append(Y[i+1]-Y[i])
    
if n > 2:
    Xd[1] = 2*Xd[0] + 2*Xd[1]
    for i in range(n-3):
        Xd[i+2] = 2*Xd[i+1] - Xd[i] + (i+3)*Xd[i+2]
        Xd[i+2] %= mod
        
if m > 2:
    Yd[1] = 2*Yd[0] + 2*Yd[1]
    for i in range(m-3):
        Yd[i+2] = 2*Yd[i+1] - Yd[i] + (i+3)*Yd[i+2]
        Yd[i+2] %= mod
    
print(Xd[-1]*Yd[-1]%mod)

Measured memory_bytes: 87524
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int x[]={1,-1,0,0};
int y[]={0,0,-1,1};
int x2[]={1,-1,0,0,1,-1,1,-1};
int y2[]={0,0,-1,1,1,-1,-1,1};
int bx[]={0,0,1,-1,-1,1,1,-1};
int by[]={1,-1,0,0,-1,-1,1,1};
int kx[] = {1,1,2,2,-1,-1,-2,-2};
int ky[] = {2,-2,1,-1,2,-2,1,-1};

bool isvisited(int x,int y)
{
    if(x<1 || y<1 || x>n ||y>m)
    {
        return false;
    }
    else if(check2[x][y]==true)
    {
        return false;
    }
    else true;
}
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(c>= a && b>=c )
    {
        printf("Yes\n");
    }
    else cout<<"No";

}






Measured memory_bytes: 3584
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
sx,sy,tx,ty=map(int,input().split())
h=ty-sy
w=tx-sx

ans=""
ans+="R"*w+"U"*h
ans+="L"*w+"D"*h
ans+="D"
ans+="R"*(w+1)+"U"*(h+1)+"L"
ans+="U"+"L"*(w+1)+"D"*(h+1)+"R"
print(ans)

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

using namespace std;
using ll = long long;

int main() {

	ll N, K;
	cin>>N>>K;
	ll ans = 0;
	if (N == K) {
		ans = 0;
	}
	else if (N > K) {
		ans = min(N%K, abs(K - N%K));	
	}
	else if (N < K) {
		ans = min(N, K-N);
	}
	
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int n = 0, k = 0;
  cin >> n >> k;
  int N[n] = {0};
  for(int i=0; i < k; i++){
	int d = 0;
    cin >> d;
    for(int j=0; j < d; j++){
      int tmp = 0;
      cin >> tmp;
      N[tmp-1]++;
    }
  }
  int count = 0;
  for(int c=0; c < n; c++){
    if(N[c] == 0)	count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3632
def main():
    n, *abc = map(int, open(0).read().split())
    dp = [0] * ((n + 1) * 3)
    a = 0
    b = 1
    c = 2
    for i in range(0, n * 3, 3):
        dp[i + a + 3] = max(dp[i + b], dp[i + c]) + abc[i + a]
        dp[i + b + 3] = max(dp[i + c], dp[i + a]) + abc[i + b]
        dp[i + c + 3] = max(dp[i + a], dp[i + b]) + abc[i + c]
        a,b,c = b,c,a
    #print(dp)
    print(max(dp[-1], dp[-2], dp[-3]))

main()

Measured memory_bytes: 35392
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int w;
	while(scanf("%d", &w), w!=-1){
		const int cost[] = {0, 125, 140};
		int c = 1150;
		rep(i, 3){
			int d = min(10, w);
			w -= d;
			c += d * cost[i];
		}
		c += w * 160;
		printf("%d\n", 4280-c);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
using namespace std;
int H,W;
int main(){
	while(cin >> H >> W && H>0){
		string s,t;
		for(int i=0;i<W;i++){
			if(i%2==1){
				s += '#';
				t += '.';
			}else{
				t += '#';
				s += '.';
			}
		}
		for(int i=0;i<H;i++){
			if(i%2==1) cout << s << endl;
			else cout << t << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3228
while True:
    n,x = map(int,raw_input().split())
    if n == 0 and x == 0:
        break

    count = 0 

    for i in range(1,n+1):
        for j in range(1,i):
            for k in range(1,j):
                if i+j+k == x:
                    count += 1
    print('{0}'.format(count))

Measured memory_bytes: 6372
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] params = sc.nextLine().split(" ");
        int a = Integer.parseInt( params[0] );
        int b = Integer.parseInt( params[1] );
        int c = Integer.parseInt( params[2] );

        if( a == b && b == c ){
            System.out.println( "No" );
            return;
        }

        if( a != b && b != c && c != a ){
            System.out.println( "No" );
            return;
        }

        System.out.println( "Yes" );

    }

}


Measured memory_bytes: 21972
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i =(a) ; i <= (b); i++)
#define ROF(i,a,b) for(int i =(b) ; i >= (a); i--)
#define REP(i,n)  FOR( i, 0, (n) - 1 )
#define PER(i,n)  ROF( i, 0, (n) - 1 )

int main(){
    int N,H[21],max=0,ans=0;
    cin >> N;
    REP(i,N){
        cin >> H[i];
        if(max <= H[i]){
            ans++;
            max = H[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  int arr[100];
  int input;
  int i, j;

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

  for(j = i - 1; j >= 0; j--){
    printf("%d", arr[j]);
    if(j != 0){
      printf(" ");
    }
  }
  printf("\n");
  
  return 0;
}




Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	int n = sz(s); int m = sz(t);
	vector<VE>is(26); rep(i, n)is[s[i] - 'a'].push_back(i);
	rep(i, n)is[s[i] - 'a'].push_back(i + n);
	int ans = 0, p = 0;
	rep(i, m) {
		int c = t[i] - 'a'; if (sz(is[c]) == 0) { COUT(-1); return 0; }
		p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
		if (p >= n) { p -= n; ans += n; }
	}
	ans += p; COUT(ans);
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
int main(void){

    vector<string> t(100);
    vector<string> s(100);
    int i,j,k,N; cin >> N;
    for(i = 0;i < N;i++){
        cin >> t.at(i);
    }

    int M; cin >> M;
    for(i = 0;i < M;i++){
        cin >> s.at(i);
    }   

    vector<int> count(100,0);
    for(i = 0;i < N;i++){
        for(j = 0;j < N;j++){
            if(t.at(i) == t.at(j))
                count.at(i)++;
        }
        for(k = 0;k < M;k++){
            if(t.at(i) == s.at(k))
                count.at(i)--;
        }
    }

    int max = count.at(0);
    int maxnum = 0;
    for(i = 0;i < N;i++){
        if(count.at(i) > max){
            max = count.at(i);
            maxnum = i;
        }
    }

    if(max > 0)
        cout << max << endl;
    else
        cout << "0" << endl;

    return 0;
}

Measured memory_bytes: 256
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a,b,n = map(int,input().strip().split())
    if n < b-1:
        print(a*n//b)
    else:
        print( (a * (b-1) ) // b )
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 78480
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
ret = []
for i in range(N, 0, -1):
  if (sum(B[i-1::i])%2) != A[i-1]:
    B[i-1]= 1
    ret.append(i)
print(sum(B))
print(*ret)

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

int main()
{
	int n, m;
	cin >> n >> m;
	int ans = 0;
	vector<int> a(n);
	
	for(int i = 0; i < m; i++)
	{
		int k;
		cin >> k;
		
		for(int j = 0; j < k; j++)
		{
			int s;
			cin >> s;
			--s;
			a[s] |= 1 << i;
		}
	}
	
	int p = 0;
	
	for(int i = 0; i < m; ++i)
	{
		int x;
		cin >> x;
		p |= x << i;
	}
	
	for(int s = 0; s < (1 << n); ++s)
	{
		int t = 0;
		
		for(int i = 0; i < n; i++)
		{
			if(s >> i & 1)
				t ^= a[i];
		}
		
		if(t == p)
			++ans;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin

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

li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]


max_n = 10**7
min_n = -1*10**7

for i in range(m):
    if li[i][0] > max_n or li[i][1] < min_n:
        print(0)
        exit()
    else:
        max_n = min(max_n,li[i][1])
        min_n = max(min_n,li[i][0])

print(max_n - min_n + 1)

Measured memory_bytes: 27348
#include <iostream>

using namespace std;

int const NMAX = 100;
long long v[1 + NMAX];

int main() {

  string s;
  int n, ans = 0;
  cin >> n;
  for(int i =1 ;i <= n;i++){
    cin >> v[i];
  }
  for(int i = 1;i <= n;i++){
    for(int j= i+1;j <= n;j++){
      for(int k =j+1;k <= n;k++){
        if(i != j && j != k && k != i && v[i] != v[j] && v[j] != v[k] && v[k] != v[i]){
          if(v[i] < v[j] + v[k] && v[j] < v[i] + v[k] && v[k] < v[i] + v[j]){
            ans++;
            //cerr << i << ' ' << j << ' ' << k << '\n';
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		double x, y;
		String st;
		int tmp;

		a = 0;
		b = 0;
		x = 0.0;
		y = 0.0;
		tmp = 0;
		st = sc.next();
		for (int i = 0; i < st.length(); i++) {
			a *= 10;
			a += st.charAt(i) - '0';
			if (st.charAt(i + 1) == ',') {
				if (st.charAt(i + 2) != '-') {
					for (int j = i + 2; j < st.length(); j++) {
						b *= 10;
						b += st.charAt(j) - '0';
					}
				} else {
					for (int j = i + 3; j < st.length(); j++) {
						b *= 10;
						b -= st.charAt(j) - '0';
					}
				}
				break;
			}
		}
		while (a + b != 0) {
			x += a * Math.sin(Math.toRadians(tmp));
			y += a * Math.cos(Math.toRadians(tmp));

			st = sc.next();
			tmp += b;
			a = 0;
			b = 0;
			for (int i = 0; i < st.length(); i++) {
				a *= 10;
				a += st.charAt(i) - '0';
				if (st.charAt(i + 1) == ',') {
					if (st.charAt(i + 2) != '-') {
						for (int j = i + 2; j < st.length(); j++) {
							b *= 10;
							b += st.charAt(j) - '0';
						}
					} else {
						for (int j = i + 3; j < st.length(); j++) {
							b *= 10;
							b -= st.charAt(j) - '0';
						}
					}
					break;
				}
			}
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const static int64 INF = 1LL << 55;

int64 N, W[4001];
int64 dp[4000][4000];
int pos[4000][4000];


int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    for(int j = i; j < N; j++) dp[i][j] = INF;
  }
  for(int i = 0; i < N; i++) {
    cin >> W[i + 1];
    W[i + 1] += W[i];
    dp[i][i] = 0;
    pos[i][i] = i;
  }
  for(int i = 2; i <= N; i++) {
    for(int j = 0; j <= N - i; j++) {
      int left = j, right = j + i - 1;
      for(int k = pos[left][right - 1]; k <= pos[left + 1][right]; k++) {
        int64 Next = dp[left][k] + dp[k + 1][right] + W[right + 1] - W[left];
        if(dp[left][right] > Next) {
          dp[left][right] = Next;
          pos[left][right] = k;
        }
      }
    }
  }
  cout << dp[0][N - 1] << endl;
}

Measured memory_bytes: 187700
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int g[200002][2];
ll ans,l;
int dfs(int v,int d){
    if(g[v][0]==-1&&g[v][1]==-1) return 0;
    else if(g[v][0]==-1) ans^=(l-d)&-(l-d),dfs(g[v][1],d+1);
    else if(g[v][1]==-1) ans^=(l-d)&-(l-d),dfs(g[v][0],d+1);
    else {
        dfs(g[v][1],d+1);
        dfs(g[v][0],d+1);
    }
}
int main(){
    int n;
    string si;
    cin>>n>>l;
    int cnt=1;
    rep(i,200002)rep(j,2) g[i][j]=-1;
    rep(i,n){
        cin>>si;
        int v=0;
        rep(j,si.size()){
            int c=si[j]-'0';
            if(g[v][c]==-1) g[v][c]=cnt,++cnt;
            v=g[v][c];
        }
    }
    ans=0;
    dfs(0,0);
    if(ans==0) cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  long long N;
  scanf("%lld", &N);
  std::vector<pair<int, int>> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  vector<vector<ll>> c(H + 2, vector<ll>(W + 2, 0));
  for (int i = 0; i < H + 2; ++i)
    c[i][0] = c[i][W + 1] = INF;
  int y = 1, x = 1;
  for (int i = 0; i < N; ++i)
  {
    while (a[i].first)
    {
      c[y][x] = a[i].second;
      a[i].first--;
      if (!c[y][x + 1])
        x++;
      else if (!c[y][x - 1])
        x--;
      else
        y++;
    }
  }
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      cout << c[i + 1][j + 1] << " \n"[j + 1 == W];

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};


int main(void){
    string S;
    cin >> S;
    int x,y;
    cin >> x >> y;
    vector<int> X, Y;
    S += 'T';
    S += 'T';
    int cnt = 0;
    bool turn = 1;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'F'){
            cnt++;
        }else{
            if(turn){
                X.push_back(cnt);
                cnt = 0;
                turn = 0;
            }else{
                Y.push_back(cnt);
                cnt = 0;
                turn = 1;
            }
        }
    }
    
    bool ans = 1;
    //Xを用いてxを作る
    vector<bool> dp1(16000, 0);
    vector<bool> next1(16000, 0);
    dp1[8000+X[0]] = 1;
    for(int i = 1; i < X.size(); i++){
        for(int j = 0; j < 16000; j++){
            if(dp1[j]){
                if(j - X[i] >= 0){
                    next1[j-X[i]] = 1;
                }
                if(j+X[i] < 16000){
                    next1[j+X[i]] = 1;
                }
            }
        }
        dp1 = next1;
        for(int j = 0; j < 16000; j++){
            next1[j] = 0;
        }
    }
    if(!dp1[8000+x]) ans = 0;
    
    vector<bool> dp2(16000, 0);
    vector<bool> next2(16000, 0);
    dp2[8000] = 1;
    for(int i = 0; i < Y.size(); i++){
        for(int j = 0; j < 16000; j++){
            if(dp2[j]){
                if(j - Y[i] >= 0){
                    next2[j-Y[i]] = 1;
                }
                if(j+Y[i] < 16000){
                    next2[j+Y[i]] = 1;
                }
            }
        }
        dp2 = next2;
        for(int j = 0; j < 16000; j++){
            next2[j] = 0;
        }
    }
    if(!dp2[8000+y]) ans = 0;
    
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    L=["SUN","MON","TUE","WED","THU","FRI","SAT"]
    S=input()
    ans=0
    for i in range(7):
        if S==L[i]:
            ans=7-i
            
    print(ans)

main()


Measured memory_bytes: 38384
n = int(input())
arr = []
for i in range(0 , n):
	arr.append(int(input()))
gp =[]
p=0
for i in range(0 ,n):
	arr[i]=arr[i]-1
cnt =0
vis =[0 for i in range(0 , n+1)]
while True:
	if p==1:
		print (cnt)
		break
	if cnt>=n:
		print(-1)
		break
	cnt = cnt+1
	p = arr[p]



Measured memory_bytes: 85912
using System;
class aoj
{
    static void Main()
    {
        int x = int.Parse(Console.ReadLine());
        int y, z, a;
        a = x % 60;
        z = ((x - a) / 60) % 60;
        y = (x - a - (z * 60)) / 3600;
        Console.WriteLine(y + ":" + z + ":" + a);
    }
}

Measured memory_bytes: 9172
c=[]
for i in range(3):
    c.append([int(j) for j in input().split(" ")])

if c[1][0]==c[0][0]+c[1][1]-c[0][1] and c[2][0]==c[0][0]+c[2][2]-c[0][2] and c[2][1]==c[1][1]+c[2][2]-c[1][2]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
use input::Input;

fn main() {
    let mut input = Input::default();

    let s = input.parse::<String>();
    println!("{}", &s[0..3]);
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  for (int i = 0; i < (1 << 4); i++) {
    int d = s[0] - '0';
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) d += s[j + 1] - '0';
      else d -= s[j + 1] - '0';
    }
    if (d == 7) {
      for (int k = 0; k < 4; k++) {
        cout << s[k];
        if (i & (1 << k)) cout << '+';
        else if (k < 3)cout << '-';
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
} 

Measured memory_bytes: 256
h,n=map(int,input().split())
a=[]
b=[]
for _ in range(n):
    i,j = map(int,input().split())
    a.append(i)
    b.append(j)

dp=[float("inf") for _ in range(h+1)]
dp[0]=0
for i in range(h+1):
    for j in range(n):
        if i-a[j]<=0:
            dp[i] = min(dp[i],dp[0]+b[j])
        else:
            dp[i] = min(dp[i],dp[i-a[j]]+b[j])
print(dp[-1])

Measured memory_bytes: 42860
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 15
#define LL long long

int d;
LL ans;

int main() {
	d = read();
	
	if(d % 9) return puts("0"), 0;
	d /= 9;
//	printf("d: %d\n", d);
	LL ini = 0, ten = 1;
	for(int i = 1; i <= 17; i++) {
		LL tmp = 1, D = d;
		ini = ini * 10 + 1;
		LL base = ini, lten = ten, rten = 1;
		for(int j = 0; j <= (i >> 1); j++) {
//			printf("%lld * %lld [tmp *= %lld] (%lld)\n", base, D % (rten * 10) / rten, 10 - abs(D % (rten * 10) / rten) - (!j ? 1 : 0), D);
			tmp *= 10 - abs(D % (rten * 10) / rten) - (!j ? 1 : 0);
			D -= base * (D % (rten * 10) / rten);
			base -= lten + rten;
			lten /= 10; rten *= 10;
		}
//		printf("%lld * %d (%lld)\n", base, D % (rten * 10) / rten, D);
		ten *= 10;
//		printf("(%lld %lld)\n", ini, tmp);
		if(!D) ans += tmp;
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

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

using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<int> v(n);
        vector<int> sum(n + 1);
        REP(i, n) {
            cin >> v[i];
            sum[i + 1] = sum[i] + v[i];
        }
        bool dp[102][102] = {};
        REP(i, n) dp[i][i + 1] = true;
        for(int l = 2; l <= n; l++) {
            for(int b = 0; b + l <= n; b++) {
                int e = b + l;
                for(int k = b + 1; k < e; k++) {
                    if(dp[b][k] && dp[k][e] && (sum[k] - sum[b]) == (sum[e] - sum[k])) {
                        dp[b][e] = true;
                    }
                }
            }
        }
        int dp2[102] = {}; // dp[i] = v[0, i) が終わるまで
        REP(i, n + 1) dp2[i] = INT_MAX;
        dp2[0] = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 0; j < i; j++) {
                if(dp[j][i]) {
                    dp2[i] = min(dp2[i], dp2[j] + 1);
                }
            }
        }
        cout << dp2[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
        t: chars,
    };
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int max=Math.max(Math.max(a+b, a-b), a*b);
		System.out.println(max);
	}
}

Measured memory_bytes: 23124
import sys
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = [0] * (N + 1)
cb = [0] * (N + 1)
for x in a: ca[x] += 1
for x in b: cb[x] += 1
for i in range(1, N + 1):
  if ca[i] + cb[i] > N:
    print("No")
    exit(0)

res = [0] * N
h = []
for i in range(1, N + 1):
  if cb[i]:
    r = N - ca[i] - cb[i] + 1
    hpush(h, (r, i))
#print(h)
s = []
table = [0] * (N + 1)
use = [0] * (N + 1)
for i in range(N):
  table[a[i]] += 1
  if len(s) and s[-1] != a[i]:
    x = s.pop()
    hpush(h, (N - ca[x] - cb[x] + 1 + table[x] + use[x], x))
  if len(h) == 0:
    print("No")
    exit(0)
  r, x = hpop(h)
  if x == a[i]:
    s.append(x)
    if len(h) == 0:
      print("No")
      exit(0)
    r, x = hpop(h)
  while r != N - ca[x] - cb[x] + 1 + table[x] + use[x]:
    hpush(h, (N - ca[x] - cb[x] + 1 + table[x] + use[x], x))
    r, x = hpop(h)
  res[i] = x
  use[x] += 1
  if cb[x] - use[x]: hpush(h, (r + 1, x))
  #print(res, h, s)
for i in range(N):
  if res[i] == a[i]:
    print("No")
    break
else:
  print("Yes")
  print(*res)

Measured memory_bytes: 120484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //コンストラクタ
  union_find(ll n) {
    for (ll i = 0; i < n; i++) {
      parent.push_back(i);
      sizes.push_back(1);
    }
  }

  //頂点nの根
  ll root_of(ll n) {
    if (parent[n] == n) return n;
    return /*parent[n] = */root_of(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size_of(ll n) {return sizes[root_of(n)];}

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {return (root_of(a) == root_of(b));}

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    if (size_of(a) < size_of(b)) swap(a, b);
    sizes[root_of(a)] += size_of(b);
    parent[root_of(b)] = root_of(a);
  }
};

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  union_find uf(n);
  vector<vll> nx(n, vll(0));
  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
    nx[a - 1].push_back(b - 1);
    nx[b - 1].push_back(a - 1);
  }
  vll bl(n, 0);
  for (ll i = 0; i < k; i++) {
    ll c, d;
    cin >> c >> d;
    if (uf.is_united(c - 1, d - 1)) {
      bl[c - 1]++;
      bl[d - 1]++;
    }
  }
  for (ll i = 0; i < n - 1; i++) cout << uf.size_of(i) - 1 - nx[i].size() - bl[i] << " ";
  cout << uf.size_of(n - 1) - 1 - nx[n - 1].size() - bl[n - 1] << endl;
}

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


int main() {
  ll A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  //bool ans = false;
  //ll dis1 = 4;
  /*
  rep(i,T){
    dis1 = abs(B-A) - (V-W)*(i+1);
    if(dis1==0){
      ans = true;
    }
  }
  if(ans){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }*/
  if(abs(B-A) <= (V-W)*T){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3640
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector<int>
#define vll vector<ll>
#define dt cout << "HERE\n";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpi vector<pll>
#define vpl vector<pll>
#define fi first
#define se second
#define sz size
#define len length

const ll inf = 1e18 + 1e17;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}
ll powm(ll a, ll b)
{
    a = a % mod;
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return (res % mod);
}

const ll N = 3e5 + 6;
bool comp(pii p1, pii p2)
{
    return p1.fi < p2.fi;
}
bool comp2(pii p1, pii p2)
{
    return p1.se > p2.se;
}
pii find(string &s)
{
    int c1 = 0, c2 = 0, n = s.len();
    for (int i = 0; i < n; i++)
    {
        if (s[i] == ')' && c2 == 0)
            c1++;
        else if (s[i] == ')' && c2 > 0)
            c2--;
        else
            c2++;
    }
    return mp(c1, c2);
}
void solve()
{
    int n;
    cin >> n;
    vpi v;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        pii p = find(s);
        v.pb(p);
    }
    //	for ( int i=0;i<v.sz();i++)
    //		cout<<v[i].fi<<' '<<v[i].se<<'\n';
    int ss = 0;
    for (int i = 0; i < n; i++)
    {
        if (v[i].fi == 0)
            ss += v[i].se;
    }
    vpi vc, vd;
    for (int i = 0; i < n; i++)
        if (v[i].fi != 0 && v[i].se - v[i].fi >= 0)
            vc.pb(v[i]);
        else if (v[i].fi != 0)
            vd.pb(v[i]);

    sort(vc.begin(), vc.end(), comp);
    for (int i = 0; i < vc.sz(); i++)
    {
        ss -= vc[i].fi;
        if (ss < 0)
        {
            cout << "No\n";
            return;
        }
        ss += vc[i].se;
    }

    sort(vd.begin(), vd.end(), comp2);
    for (int i = 0; i < vd.sz(); i++)
    {
        ss -= vd[i].fi;
        if (ss < 0)
        {
            cout << "No\n";
            return;
        }
        ss += vd[i].se;
    }

    if (ss == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //	#ifndef ONLINE_JUDGE
    //		cin.tie(NULL);
    //		freopen ("INPUT.txt" , "r" , stdin);
    //		freopen ("OUTPUT.txt", "w" , stdout);
    //	#endif
    ll t = 1;
    // cin>>t;
    for (ll i = 1; i <= t; i++)
    {
        //	cout<<"Case #"<<i<<": ";
        solve();
    }
}


Measured memory_bytes: 34732