akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn=200005;
int a[maxn];
int main(){
	int n;
	int mx=-2000000000,mn=0x3f3f3f3f;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	mn=a[1];
	for(int i=2;i<=n;i++){
		mx=max(mx,a[i]-mn);
		mn=min(mn,a[i]);
	}
	cout<<mx<<endl;
	return 0;
}


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

#define int long long

int32_t main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));

  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const long long  mod = 1e9+7;
map<long long ,long long>dp;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
long long Dp(long long x)
{
    if(dp[x])return dp[x];
    else
    {
        return dp[x] = ((Dp(x/2)+Dp((x-1)/2)+Dp((x-2)/2)) )%mod;
    }
}
int main()
{
    dp[0] = 1;
    dp[1] = 2;
    long long n;
    cin>>n;
    cout<<Dp(n);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int main(){
    int n,k,q,x;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++){
        a[i]=k-q;
    }
    while(q--){
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

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

int main() {
    // 入力
    int A,B,C,X;
    int cnt = 0;
    cin >> A >> B >> C >> X;

    for(int i = 0; i <= A; i++){
      for(int j = 0; j <= B; j++){
        for(int k = 0; k <= C; k++){
          if(i*500 + j*100 + k*50 == X) cnt++;
        }
      }
    }
    cout << cnt << endl;
}


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

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

  string answer = "";

  if (a == "H") {
    if (b == "H") {
      answer = "H";
    } else {
      answer = "D";
    }
  } else {
    if (b == "H") {
      answer = "D";
    } else {
      answer = "H";
    }
  }

  cout << answer << endl;

}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	ll K, ans = 0;
	
	cin >> N >> K;
	
	int A[N];
	
	rep(i, N)
		cin >> A[i];
		
	rep(i, N){
		rep(j, N){
			if(i == j)
				continue;
			if(i < j && A[i] > A[j])
				ans += ((K * (K + 1)) / 2) % mod;
			else if(i > j && A[i] > A[j])
				ans += (((K - 1) * K) / 2) % mod;
		}
		ans %= mod;
	}
	
	cout << ans % mod;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(P);
		Console.WriteLine(P.Take(K).Sum());
		
		
	}
	int N,K;
	long[] P;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		P = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 19608
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> P;

ll dp[1000][1000] = {};

int main(){
    int h, w, i, j;
    char c;
    cin >> h >> w;
    dp[0][0] = 1;
    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            cin >> c;
            if(c == '#') dp[i][j] == 0;
            else{
              	if(i == 0 && j == 0) continue;
                else if(i == 0) dp[i][j] = dp[i][j-1];
                else if(j == 0) dp[i][j] = dp[i-1][j];
                else dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[h-1][w-1] << "\n";
    return 0;
}

Measured memory_bytes: 8064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,dis; cin>>n;
    vector<int> me(n+1,-1);
    int ad;
    rep(i,n+1){
        cin>>ad;
        if(me[ad]>=0){
            dis=i-me[ad]+1; break;
        }
        else{
            me[ad]=i;
        }
    }
    vector<ll> v(n+2,0); v[1]=1;
    for(int i=2;i<=n+1;i++){
        v[i]=(-v[MOD%i]*(MOD/i))%MOD;
    }
    ll c=1,d=1;
    rep(i,n+1){
        c=((c*(n+1-i))%MOD)*v[i+1]%MOD;
        c=(c+MOD)%MOD;
        cout<<(c-d+MOD)%MOD<<endl;
        d=((d*(n+1-dis-i))%MOD)*v[i+1]%MOD;
        d=(d+MOD)%MOD;
    }
}

Measured memory_bytes: 2432
from collections import deque

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
s,d = 0,deque()

d.append(A[0])
for i in range(1,N):
	s += d.popleft()
	d.append(A[i])
	d.append(A[i])
print(s)

Measured memory_bytes: 106764
#include <iostream>

using namespace std;


int h,w,a[100][100];


char input(char c)
{
    while (c=='\n') c=getchar();
    return(c);
}

void deal(int i,int j)
{
    int h1=i-1>=0?i-1:0;
    int h2=i+1<h?i+1:h-1;
    int w1=j-1>=0?j-1:0;
    int w2=j+1<w?j+1:w-1;
    for (int ii=h1;ii<=h2;ii++)
        for (int jj=w1;jj<=w2;jj++)
            if (a[ii][jj]!=-1) a[ii][jj]++;
}

int main()
{
    char c;
    scanf("%d%d",&h,&w);
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            {
                c=input(getchar());
                if (c=='.') a[i][j]=0;
                else a[i][j]=-1;
            }
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            if (a[i][j]==-1) deal(i,j);
    for (int i=0;i<h;i++)
        {
            for (int j=0;j<w;j++) if (a[i][j]==-1) printf("#");
            else printf("%d",a[i][j]);

            printf("\n");
        }


    return 0;
}


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

struct city{
    int num;
    int year;
    int prefecture;
    int order; //県で何番目か
};

bool comp1(city a, city b){
    if(a.prefecture == b.prefecture) return ( a.year < b.year);
    return (a.prefecture < b.prefecture);
}

bool comp2 (city a, city b){
    return a.num < b.num;
}

void pr(int K){
    int K1 =K;
    int digit =0;
    while(K>0){
        K /=10;
        digit++;
    }
    for(int i=0; i<(6-digit); i++){
        cout << 0;
    }
    cout << K1;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<city> C(M);
    for(int i=0; i<M; i++){
        C.at(i).num =i;
        cin >> C.at(i).prefecture;
        cin >> C.at(i).year;
    }
    sort(C.begin(),C.end(),comp1);

    int cnt=1;
    C.at(0).order=1;
    for(int i=1;i<M;i++){
        if(C.at(i).prefecture==C.at(i-1).prefecture){
            C.at(i).order = C.at(i-1).order+1;
        }
        else C.at(i).order =1;
    }

    sort(C.begin(),C.end(),comp2);

    for(int i=0; i<M; i++){
        pr(C.at(i).prefecture);
        pr(C.at(i).order);
        cout << endl;
    }
}

Measured memory_bytes: 3072
a=int(input())
if a==11 or a==13 or a==17 or a==19 or a==22 or a==23 or a==26 or a==29 or a==31 or a==33 or a==34 or a==37 or a==38 or a==39 or a==41 or a==43 or a==44 or a==46 or a==47 or a==50 or a==51 or a==52 or a==53 or a==55 or a==57 or a==58 or a==59 or a==60 or a==61 or a==62 or a==65 or a==66 or a==67 or a==68 or a==69 or a==70 or a==71 or a==73 or a==74 or a==75 or a==76 or a==77 or a==78 or a==79 or a==80 or a>=82:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 1940
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    A, B, C, K = map(int, readline().split())
    if K&1==0:
        print(A-B)
    else:
        print(B-A)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int w = sc.nextInt();
        int[][] arr = new int[n][2];

        for (int i=0; i<n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        long[][] dp = new long[n+1][n*1000+1];

        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n*1000+1; j++) {
                dp[i][j] = Integer.MAX_VALUE;
            }
        }

        dp[0][0] = 0;

        for (int i=1; i<=n; i++) {
            for (int j=0; j<=n*1000; j++) {
                if (j < arr[i-1][1]) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = Math.min(dp[i-1][j], dp[i-1][j-arr[i-1][1]] + arr[i-1][0]);
                }
            }
        }

        int ret = 0;

        for (int i=0; i<=n*1000; i++) {
            if (dp[n][i] <= w) ret = i;
//            System.out.println(dp[n][i]);
        }

        System.out.println(ret);

    }
}



Measured memory_bytes: 127056
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

string S,T;
void solve() {
  cin >> S >> T;
  cout << T << S <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll d=c-a-b;
	if(d<0){
		cout<<"No"<<endl;
		return 0;
	}
	if(d*d>(ll)4*a*b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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



int main() {


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

	if (a >= 6 && a <= 12)
		printf("%d\n", b / 2);
	else if (a <= 5)
		printf("0\n");
	else
		printf("%d\n",b);


	

	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char grid[30][30];
int h, w;

int bfs(pair<int, int> start){
	queue<pair<int, int>> q;
	int dist[30][30];
	memset(dist, -1, sizeof(dist));
	dist[start.first][start.second] = 0;
	int dx[4] = {1, -1, 0, 0};
	int dy[4] = {0, 0, 1, -1};
	q.push(start);
	int distn;
	while(!q.empty()){
		pair<int, int> now = q.front();
		q.pop();
		distn = dist[now.first][now.second];
		for (int i = 0; i < 4; i++) {
			if (now.first + dx[i] >= 0 && now.first + dx[i] < h
			&& now.second + dy[i] >= 0 && now.second + dy[i] < w
			&& dist[now.first + dx[i]][now.second + dy[i]] == -1
			&& grid[now.first + dx[i]][now.second + dy[i]] == '.') {
				q.push(make_pair(now.first + dx[i], now.second + dy[i]));
				dist[now.first + dx[i]][now.second + dy[i]] = distn + 1;
			}
		}
	}
	// for (int i = 0; i < h; i++) {
	// 	for (int j = 0; j < w; j++) {
	// 		cout<<dist[i][j]<<' ';
	// 	}
	// 	cout<<'\n';
	// }
	// cout<<'\n';		
	return distn;
}

int main(int argc, char const *argv[]) {
	// ios::sync_with_stdio(false);
	// cin.tie(NULL);
	cin>>h>>w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin>>grid[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			// cout<<i<<';'<<j<<'\n';
			if (grid[i][j] == '.') {
				ans = max(ans, bfs(make_pair(i, j)));
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
function writedown(x)
		print("#")
		print(x)
		print("#")
		println()
end

function main()
	h,w = parse.(split(readline()))
	for i in 1:w+2
		print("#")
	end
	println()
	for i in 1:h
		writedown(chomp(readline()))
	end
	for i in 1:w+2
		print("#")
	end
	println()
end

main()

Measured memory_bytes: 119684
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = 0;
        int max = 0;
        String s = sc.next();
        for(int i =0;i<n;i++) {
            if("I".equals(s.substring(i,i+1))) {
                x++;
            } else {
                x--;
            }
            max = Math.max(max, x);
        }
        System.out.println(max);
    }
}

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

typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 200005

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll n,i,a[N],sum=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ll ans=2e9,pre_sum=0;
	for(i=0;i<n-1;i++){
		pre_sum+=a[i];
		ans = min(ans,abs(sum-2*pre_sum));
	}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();

        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;

        for(int i = 0; i < n; i++) {
            switch(sc.next()) {
                case "AC":
                 ac++;
                 break;
                case "WA":
                 wa++;
                 break;
                case "TLE":
                 tle++;
                 break;
                case "RE":
                 re++;
                 break;
                default:
                 break;
            }

        }

        System.out.println("AC x " + String.valueOf(ac));
        System.out.println("WA x " + String.valueOf(wa));
        System.out.println("TLE x " + String.valueOf(tle));
        System.out.println("RE x " + String.valueOf(re));
    }
}

Measured memory_bytes: 58736
#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n;cin >> n;ll sum = 0;
	vector<ll> a(n),c(n,0);
	rep(i, n) {
		cin >> a[i];a[i]--;
		c[a[i]]++;
	}
	rep(i, n) sum += c[i] * (c[i] - 1) / 2;
	rep(i,n) cout << sum - c[a[i]] + 1 << endl;
}

Measured memory_bytes: 5760
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c>(a-b))cout<<c-(a-b);
  else cout<<0;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N, M;
    cin >> N >> M;
    lint res;
    if (N == 1 && M == 1) {
        res = 1;
    }
    else if (N == 1) {
        res = M - 2;
    }
    else if (M == 1) {
        res = N - 2;
    }
    else {
        res = (N - 2) * (M - 2);
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
def solve():
    import itertools
    from operator import itemgetter

    N = int(input())
    B = [input() for _ in range(N)]
    B.sort()

    l = []
    gr = itertools.groupby(B)
    max_key = 0
    for key, group in gr:
        length = len(list(group))
        l.append((length, key))
        if length > max_key:
            max_key = length

    l.sort(key = itemgetter(0), reverse=True)

    key = l[0][0]
    for k, v in l:
        if key == k:
            print(v)
        else:
            break

solve()

Measured memory_bytes: 34180
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;


int main()
{
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i< n; i++) {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    int index = n / 2;
    vector<int> res(n);
    copy(a.begin(), a.end(), res.begin());

    for (int i = index; i > 0; i--) {
        int sum = 0;
        for (int j = n / i ; j > 1; j--) {
            sum += res[i * j - 1];
        }
        res[i - 1] = (sum % 2 + a[i - 1] == 1) ? 1 : 0;
    }
    int m = accumulate(res.begin(), res.end(), 0);
    cout << m << endl;
    for (int k = 0; k < n; k++) {
        if (res[k] == 1) {
            cout << k + 1 << endl;
        }
    }
}



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

int main() {
	long long int N, M;
	cin >> N >> M;
	vector<long long int>c( M );
	vector<long long int>dp( N + 1 );
	dp[0] = 1;
	for( size_t i = 0; i < M; i++ ) {
		cin >> c[i];
		for( size_t j = 0; j < N + 1; j++ ) {
			if( dp[j] && j + c[i] < N + 1 ) {
				if( dp[j + c[i]] )
					dp[j + c[i]] = min( dp[j + c[i]], dp[j] + 1 );
				else
					dp[j + c[i]] = dp[j] + 1;
			}
		}
	}
	cout << dp[N] - 1 << endl;
}

Measured memory_bytes: 3088
N, T, E = map(int, input().split())
X = list(map(int, input().split()))

time = [i for i in range(T - E, T + E + 1)]

clock = -2

for i in range(len(X)) :
    for j in range(len(time)) :
        if time[j] % X[i] == 0 :
            clock = X.index(X[i])
            
print(clock + 1)
            


Measured memory_bytes: 5624
#include "bits/stdc++.h"

using namespace std;
 
const long long inf = 1e18;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;

ll n,m,k;
ll dp[101][300001];
vector <pair<int,int> > in;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	k = 0;
	fr(i,0,n) {
		int w,v;
		cin >> w >> v;
		k += v;
		in.pb({w,v});
	}
	fr(i,0,n+1) {
		fr(j,0,k+1) {
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	fr(i,0,n) {
		fr(j,0,k+1) {
			if (j + in[i].second <= k) {
				dp[i+1][j+in[i].second] = min(dp[i+1][j+in[i].second], in[i].first + dp[i][j]);
			}
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
		}
	}
	ll ans = 0;
	for (int i = 0;i <= k;i++) {
		if (dp[n][i] <= m)
			ans = i;
	}
	cout << ans << endl;
	return 0;
}

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

signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    int sum = 0;
    rep(i,n-k) sum += h[i];
    if(k>=n) sum = 0;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
input = $stdin.read.split("\n")

n = input.shift.to_i
ts = input.shift.split(" ").map(&:to_i)
as = input.shift.split(" ").map(&:to_i)

ts.unshift(0)
as.push(0)

tts = ts[1..-1]
aas = as[1..-1]

zs = tts.zip(ts, as, aas)

ns = zs.map do |t, pt, a, na|
	case 
	when t> pt && a> na && a==t
		1
	when t> pt && a> na && a!=t
		puts 0
		exit
	when t> pt && a==na && t<=a
		1
	when t==pt && a> na && t>=a
		1
	when t==pt && a==na
		[t, a].min
	else
		puts 0
		exit
	end
end

puts ns.inject { |a,b| (a*b) % (10**9 + 7) }


Measured memory_bytes: 36372
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
    using namespace std;
    //long long p = 998244353;
    long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
    vel kai(max_kai, 1);
    vel inv_kai;
    int rui(int a, int n, int mod) {
        if (n == 0) { return 1 % mod; }
        int x = rui(a, n / 2, mod);
        x *= x; x %= mod;
        if (n % 2 == 1) { x *= a; x %= mod; }
        return x;
    }
    vel pa;
    int root(int x) {
        if (pa[x] == -1) { return x; }
        int ans = root(pa[x]); pa[x] = ans;
        return ans;
    }
    void marge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) { pa[x] = y; }
    }
    int gcd(int x, int y) {
        if (x < y) { return gcd(y, x); }
        if (y == 0) { return x; }
        return gcd(y, x % y);
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
signed main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int x; cin >> x;
        if (x == ans + 1) { ans++; }
    }
    if (ans == 0) { cout << -1 << endl; }
    else { cout << n - ans << endl; }
    return 0;
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    string s;
    cin >>n>>s;

    string ans;

    ans += s[0];

    rep(i,1,n)
        if(s[i-1] != s[i]) ans += s[i];
    
    //cout << ans << endl;    
    cout << ans.size() << endl;    

    return 0;
}


Measured memory_bytes: 592
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do

    [n,k] <- (map strToInt . words) <$> getLine
    an <- map strToInt . words <$> getLine
    
    let bn =  (group (sort an))
    let cn = reverse $ sort (map (length) bn)
    print (solve cn k)


solve :: [Int] -> Int -> Int
solve cn k = if (n <= k)
             then 0
             else sum (drop k cn)
                where n = length cn


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    while (true)
    {
        string a[8];
        vector<int> tracex;
        vector<int> tracey;
        bool flag = false;
        rep(i, 8) if(!(cin >> a[i])) return 0;
        rep(i, 8)
            rep(j, 8) if (a[i][j] == '1')
        {
            tracex.push_back(j);
            tracey.push_back(i);
        }
        REP(i, 1, tracex.size())
        tracex[i] -= tracex[0];
        REP(i, 1, tracey.size())
        tracey[i] -= tracey[0];
        //tracex[0]=0;tracey[0]=0;
        if (tracex[3] == 1 && tracey[3] == 1)
            cout << "A" << endl;
        if (tracex[3] == 3)
            cout << "C" << endl;
        if (tracey[3] == 3)
            cout << "B" << endl;
        if (tracex[1] == -1 && tracey[3] == 2)
            cout << "D" << endl;
        if (tracex[3] == 2)
            cout << "E" << endl;
        if (tracex[2] == 1 && tracey[3] == 2)
            cout << "F" << endl;
        if (tracex[2] == -1 && tracey[2] == 1)
            cout << "G" << endl;
        if (flag)
            break;
    }
    return 0;
}

Measured memory_bytes: 3156
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <boost/multiprecision/cpp_int.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define debuga(a) cout << "debug " << a << endl;
#define debugab(a,b) cout << "debug1 " << a <<" debug2 " << b << endl;
/*void product(ll ar[], ll n)
{
  cpp_int result = 1;
  for (ll i = 0; i < n; i++)
    result = result * ar[i];
  if (result > 1000000000000000000)
    cout << -1 << endl;
  else
    cout << result << endl;
}*/
int32_t main()
{
  fast;
#ifndef ONLINE_JUDGE
  freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
  freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
  		int n; cin >> n;
	cpp_int a[n];cpp_int res = 1;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		res = res*a[i];
		if(res > 1000000000000000000)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6840
sx,sy,tx,ty = map(int,input().split())
x,y = tx-sx,ty-sy
ans = "R"*x + "U"*y + "L"*x + "D"*y + "D" +"R"*(x+1) + "U"*(y+1) + "LU" + "L"*(x+1) + "D"*(y+1) + "R"
print(ans)

Measured memory_bytes: 3060
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, k = inintm()

for i in range(a,min(b, a+k-1)+1):
    print(i)
for i in range(max(a+k, b-k+1), b+1):
    print(i)

Measured memory_bytes: 62436
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
using namespace std;
const int N=100005;
int n;
long long ans;
string s[N];
char str[N];
map<string,int> mp;
string gao(string s){
	sort(s.begin(),s.end());
	return s;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",str);
		s[i]=str;
		ans+=mp[gao(s[i])];
		mp[gao(s[i])]++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 16640
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
howmany = [0 for k in range(10**5+1)]
for k in range(N):
    howmany[A[k]] +=1

Q = int(input())
for k in range(Q):
    B, C = map(int, input().split())
    
    S += (C-B)*howmany[B]
    print(S)
    howmany[C] += howmany[B]
    howmany[B] =0

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

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

  int32_t answer = 0;
  for (int32_t i = 0; i < n; i++) {
    int32_t l, r;
    cin >> l >> r;
    answer += r - l + 1;
  }
  cout << answer << endl;
  return 0;
}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

vector<int> G[100005];

int dp[100005][2]; // 0: white, 1: black

int mod = 1e9 + 7;

int dfs(int n, int c, int p) {
    if (dp[n][c] > 0) return dp[n][c];

    int res = 1;

    REP(i, G[n].size()) {
        if (G[n][i] == p) continue;

        int child = G[n][i];
        if (c == 0) {
            // white
            res *= (dfs(child, 0, n) + dfs(child, 1, n)) % mod;
            res %= mod;
        } else {
            // black
            res *= dfs(child, 0, n);
            res %= mod;
        }
    }

    return dp[n][c] = res;
}

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

    int N;
    cin >> N;

    REP(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);

        dp[i][0] = dp[i][1] = -1;
    }

    int ans = dfs(0, 0, -1) + dfs(0, 1, -1);
    cout << ans % mod << endl;

    return 0;
}


Measured memory_bytes: 15616
use proconio::input;
use proconio::marker::Bytes;


fn main() {
    input!{
        s:Bytes
    }

    let b = s.iter().enumerate().all(
        |(i,&x)| if i%2==0 {x==b'h'} else {x==b'i'}
    );

    if s.len()%2==0 && b {
        println!("Yes");
    }
    else {
        println!("No");
    }
    
    
}



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

int num(char x) {
  int num = 0;
  if (x == 'A') {
    num = 1;
  } else if (x == 'B') {
    num = 2;
  } else if (x == 'C') {
    num = 3;
  } else if (x == 'D') {
    num = 4;
  } else if (x == 'E') {
    num = 5;
  } else {
    num = 6;
  }
  return num;
}

int main() {
  char x, y;
  cin >> x >> y;

  if (num(x) > num(y)) {
    cout << '>' << endl;
  } else if (num(x) < num(y)) {
    cout << '<' << endl;
  } else {
    cout << '=' << endl;
  }
}


Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def root(P, C, a):
    if P[a] == a:
        return a
    r = root(P, C, P[a])
    P[a] = r
    C[a] = C[r]
    return r


def main():
    N, M = read_values()
    V = [read_list() for _ in range(M)]
    P = [i for i in range(N)]
    C = [1] * N
    res = [N * (N - 1) // 2] * M
    total = 0
    for i in range(M - 2, -1, -1):
        a, b = V[i + 1]
        a -= 1
        b -= 1

        ra = root(P, C, a)
        rb = root(P, C, b)
        if ra == rb:
            res[i] -= total
            continue

        P[ra] = rb
        total += C[ra] * C[rb]
        C[ra] += C[rb]
        C[rb] = C[ra]
        res[i] -= total

    print("\n".join(map(str, res)))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 49116
fun main(args: Array<String>) {
    val (w, h, c) = readLine()!!
        .split(" ")
        .map { it.toInt() }

    // should be a > b
    fun gcd(a: Int, b: Int): Int {
        if(a < b) return gcd(b, a)
        return if (b > 0) gcd(b, a % b) else a
    }
    val gcd = gcd(w, h)
    println(w / gcd * h / gcd * c)
}


Measured memory_bytes: 33796
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  int i, j;
  cout << 180 * (n - 2) << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

from math import ceil,floor

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

# def func(a):
#    return tmp

N,D=map(int, input().split())

r = 2 * D + 1
print(ceil(N/r))



Measured memory_bytes: 38384
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    string s;
    cin >> s;

    priority_queue<int> red;
    priority_queue<int, vector<int>, greater<int>> white;

    rep(i, N) {
        if (s[i] == 'W')
            white.push(i);
        else
            red.push(i);
    }

    int cnt = 0;

    if (red.empty() || white.empty()) {
        cout << cnt << endl;
        return 0;
    }
    while (red.top() > white.top()) {
        int r = red.top();
        red.pop();
        int w = white.top();
        white.pop();
        red.push(w);
        white.push(r);
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 4800
n = int(input())
table = [[[0] * 10 for _ in range(3)] for __ in range(4)]

for ___ in range(n):
  b, f, r, v = map(int, input().split())
  table[b - 1][f - 1][r - 1] += v 

x = 0
for i in range(4):
  if x != 0:
    print("#" * 20)
  x += 1

  for j in range(3):
    for k in range(10):
      print (" %d" %(table[i][j][k]), end = "")
    print()



Measured memory_bytes: 5624
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);
	IN_V(ll, als, n);
	IN_V(ll, bls, n);

	ll cnt = 0;
	multiset<pair<ll, ll>, greater<pair<ll, ll>>> dict;
	for (int i = 0; i < n; ++i) {
		if (bls[i] < als[i]) {
			cout << -1 << endl;
			return 0;
		}
		if(bls[i] > als[i]) dict.insert(make_pair(bls[i], i));
	}
	while (dict.size()) {
		auto target = *(dict.begin());
		auto aplusc = bls[(target.second + 1) % n] + bls[(target.second - 1 + n) % n];

		auto diffnum = (bls[target.second] - als[target.second]) / aplusc;
		cnt += diffnum;
		bls[target.second] -= diffnum * aplusc;
		dict.erase(dict.begin());
		if (diffnum == 0) {
			cout << -1 << endl;
			return 0;
		}
		if (bls[target.second] != als[target.second]) {
			dict.insert(make_pair(bls[target.second], target.second));
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 15872
def reconstruct(pre_tree,in_tree):
    if not pre_tree:
        return -1
    root = pre_tree[0]
    idx = in_tree.index(root)
    tree[root] = (
        reconstruct(pre_tree[1:idx+1],in_tree[:idx]),
        reconstruct(pre_tree[idx+1:],in_tree[idx+1:])
    )
    return root

def post_walk(idx):
    if idx == -1:
        return 
    l_idx,r_idx = tree[idx]
    yield from post_walk(l_idx)
    yield from post_walk(r_idx)
    yield idx

n = int(input())
tree = [None]*(n+1)
pre_lst = list(map(int,input().split()))
in_lst = list(map(int,input().split()))

reconstruct(pre_lst,in_lst)
print(' '.join(map(str,post_walk(pre_lst[0]))))



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

using namespace std;

bool mySort (const pair<string, int>p1, const pair<string, int> p2)
{
    return (p1.first < p2.first || p1.first == p2.first && p1.second > p2.second);
}

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

    vector<pair<string, int>> in;
    map<pair<string, int>, int> mp;

    for (int i=0; i<n; ++i)
    {
	string s; int a;
	cin >> s >> a;
	in.push_back({s, a});
	mp[make_pair(s, a)] = i+1;
    }

    sort(in.begin(), in.end(), mySort);

    for (auto &i: in)
    {
	cout << mp[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int i,a[n],d=0;
	double s=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		s=s+a[i];
	}
	s=s/n;
	s=round(s);
	for(i=0;i<n;i++)
	{
		a[i]=a[i]-s;
		d=d+a[i]*a[i];
	}
	cout<<d<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using Grid = vector<vector<int>>;
using vi = vector<int>;

int main() {
    int N, Q;
    cin >> N >> Q;
    list<tuple<int, int, int>> eve;
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        eve.emplace_back(s - x, 1, x);
        eve.emplace_back(t - x, -1, x);
    }
    eve.sort();
    multiset<int> ms;
    rep(i, Q) {
        int p;
        cin >> p;
        while (eve.size() > 0 && get<0>(eve.front()) <= p) {
            if (get<1>(eve.front()) == 1)
                ms.insert(get<2>(eve.front()));
            else
                ms.erase(get<2>(eve.front()));
            eve.pop_front();
        }
        cout << (ms.size() == 0 ? -1 : *(ms.begin())) << endl;
    }
}


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

vector<int>E[100];
bool used[200];
int match[200];

bool dfs(int u) {
	used[u] = true;
	for (int v : E[u]) {
		int w = match[v];
		if (w == -1 || (!used[w] && dfs(w))) {
			match[u] = v; match[v] = u;
			return true;
		}
	}
	return false;
}
int x[100], y[100], z[100], a[100], b[100];
double d[100][100];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n)scanf("%d%d%d", &x[i], &y[i], &z[i]);
		rep(i, m)scanf("%d%d", &a[i], &b[i]);
		rep(i, n)rep(j, m)d[i][j] = hypot(x[i] - a[j], y[i] - b[j]) / z[i];
		double l = 0, r = 15000;
		rep(i, 100) {
			double t = (l + r) / 2;
			rep(j, n) {
				E[j].clear();
				rep(k, m) {
					if (d[j][k] <= t)E[j].push_back(n + k);
				}
			}
			int cnt = 0;
			memset(match, -1, sizeof(match));
			rep(j, n) {
				if (match[j] == -1) {
					memset(used, 0, sizeof(used));
					cnt += dfs(j);
				}
			}
			if (cnt == m)r = t;
			else l = t;
		}
		printf("%.14lf\n", l);
	}
}

Measured memory_bytes: 3388
# def cmb(n, k, mod):
#     numerator = 1
#     for i in range(k):
#         numerator = (numerator * (n - i)) % mod

#     denominator = 1
#     for i in range(1, k + 1):
#         denominator = (denominator * i) % mod

#     return (numerator * pow(denominator, mod - 2, mod)) % mod


def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + i + 1 for i in range(r)]
    denominator = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= numerator[k]
    return int(result)


import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
freq = {}
for i in a:
    if i in freq:
        freq[i] += 1
    else:
        freq[i] = 1

inf = 1001001001
dp = [inf for _ in range(200005)]
dp2 = [inf for _ in range(200005)]
mod = 10**13 + 3

base = 0
for k, v in freq.items():
    if v > 2:
        dp[k] = ncr(v, 2)
        dp2[k] = ncr(v - 1, 2)
    elif v == 2:
        dp[k] = 1
        dp2[k] = 0
    else:
        dp[k] = 0
        dp2[k] = 0
    base += dp[k]

for i in a:
    print(base - dp[i] + dp2[i])


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

int main() {
	int n;
	cin >> n;
	if (n == 25) {
		cout << "Christmas" << endl;
	}
	else if (n == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (n == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (n == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
}

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

const int MAX_N = 105;
const int MAX_K = 100005;
int dp[MAX_K][2];
int a[MAX_N];
int N, K;

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < a[0]; ++i)
      dp[i][0] = dp[i][1] = 0;
  for (int k = a[0]; k <= K; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int p = 0; p < 2; ++p) {
        if (k - a[i] >= 0)
          dp[k][p] |= !dp[k-a[i]][!p];
      }
    }
  }
  printf("%s\n", dp[K][0] ? "First" : "Second");
}


Measured memory_bytes: 4516
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <climits>
#include <ctime>
#include <cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

#define sz(x) (int)(x.size())

typedef long long ll;
typedef tuple<int, int, int> tri;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef __gnu_pbds::tree<
    int,
    __gnu_pbds::null_type,
    less<int>,
    __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>
    ordered_set;

const ll MODULO = 1000000007;

void ftime()
{
#ifndef ONLINE_JUDGE
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}

static int speed_increase = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    return 0;
}();

vi arr(2e5+1);
vi len(2e5+1);

int find_parent(int a) {
    if(a != arr[a]) {
        arr[a] = find_parent(arr[a]);
    }
    return arr[a];
}

void merge(int a, int b) {
    a = find_parent(a);
    b = find_parent(b);
    if(a == b)
        return;
    if (len[a] < len[b]) {
        swap(a, b);
    }
    arr[b] = a;
    len[a] += len[b];
}


void solve()
{
    int n, m;
    cin>>n>>m;
    for(int i=1; i<=n; ++i) {
        arr[i] = i;
        len[i] = 1;
    }
    for(int i=0; i<m; ++i) {
        int a, b;
        cin>>a>>b;
        merge(a, b);
    }
    cout<<*max_element(len.begin()+1, len.begin()+n+1)<<"\n";
}

int main()
{
    solve();
    // ftime();
    return 0;
}

Measured memory_bytes: 4752
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int A,B,count=0;
  scanf("%d %d\n",&A,&B );

  if (A > B) {
    count += A;
    A--;
  } else {
    count += B;
    B--;
  }

  if (A > B) {
    count += A;
    A--;
  } else {
    count += B;
    B--;
  }
  printf("%d\n",count );
  return 0;
}


Measured memory_bytes: 128