akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int a[200005], cnt[200005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	for (int i = 0; i < n; i++) {
		cnt[a[i]]++;
	}
	
	long long res = 0;
	
	for (int i = 1; i <= n; i++) res += 1LL * cnt[i] * (cnt[i] - 1) / 2;
	
	for (int i = 0; i < n; i++) {
		int v = a[i];
		long long tmp = res;
		tmp -= 1LL * cnt[v] * (cnt[v] - 1) / 2;
		cnt[v]--;
		tmp += 1LL * cnt[v] * (cnt[v] - 1) / 2;
		cnt[v]++;
		
		printf("%lld\n", tmp);
	}
}


Measured memory_bytes: 5380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        string s = Read();
        string t = Read();
        int c = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] != t[i]) c++;
        }
        Console.WriteLine(c);
    }
}


static class Scanner
{
    static Queue<string> que = new Queue<string>();

    public static string Read()
    {
        if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
        return que.Dequeue();
    }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());
    public static decimal ReadDecimal() => decimal.Parse(Read());

    public static IEnumerable<string> Read(long n)
    {
        for (long i = 0; i < n; i++) yield return Read();
    }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
    public static IEnumerable<double> ReadDouble(long n) => Read(n).Select(double.Parse);
    public static IEnumerable<decimal> ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}

Measured memory_bytes: 28080
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<string>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define REC(ret,...) std::function<ret (__VA_ARGS__)>
template<typename T>
bool chmin(T& l, T r) {
	bool res = l > r;
	if (res)l = r;
	return res;
}
template<typename T>
bool chmax(T& l, T r) {
	bool res = l < r;
	if (res)l = r;
	return res;
}
template<typename T>
istream& operator>>(istream& is, vector<T> &v) {
	for (auto &it : v)is >> it;
	return is;
}
typedef vector<int> V;
int f(int x, int y, int z) {
	return x + y + z;
}
const int dx[4] = { 0,0,-1,1 };
const int dy[4] = { 1,-1,0,0 };
#define BBB 0
#define FFF 1
#define LLL 2
#define RRR 3
const int hiro[4][6] = {
	{0,1,5,4,2,3},
	{0,1,4,5,3,2},
	{4,5,2,3,1,0},
	{5,4,2,3,0,1}
};
typedef vector<int> V;
typedef vector<V> VV;
typedef pair<int, int> P;
void rot_move(vector<int>& state, int r, int&x, int &y) {
	x += dx[r];
	y += dy[r];
	vector<int> nxt(6);
	REP(i, 6)nxt[hiro[r][i]] = state[i];
	REP(i, 6)state[i] = nxt[i];
}				
map<int, int> memo;
inline int ch(int x, int y) {
	x += 1000;
	y += 1000;
	return x * 2123 + y;
}
int main() {
	int N;
	while (cin >> N, N) {
		V x(N), y(N);
		VV dice(N, V(6));
		vector<string> rot(N);
		REP(i, N) {
			cin >> x[i] >> y[i];
			cin >> dice[i];
			cin >> rot[i];
			for (auto &it : rot[i]) {
				if (it == 'B')it = BBB;
				if (it == 'F')it = FFF;
				if (it == 'L')it = LLL;
				if (it == 'R')it = RRR;
			}
		}
		vector<set<int>> fut(1<<N);
		REP(bit, 1 << N) {
			REP(i, N)if ((bit >> i) & 1) {
				int xx = x[i];
				int yy = y[i];
				fut[bit].insert(ch(xx, yy));
				auto v = dice[i];
				for (auto &it : rot[i]) {
					rot_move(v, it, xx, yy);
					fut[bit].insert(ch(xx, yy));
				}
			}
		}
		V dp(1 << N, -1);	
		dp[0] = 0;
		REC(int, int) dfs = [&](int bit) {
			if (dp[bit] >= 0)return dp[bit];
			dp[bit] = 0;
			REP(i, N)if ((bit >> i) & 1) {
				auto v = dice[i];
				int nxtbit = bit - (1 << i);
				int cost = dfs(nxtbit);
				int xx = x[i];
				int yy = y[i];
				memo.clear();
				if (!fut[nxtbit].count(ch(xx, yy)))memo[ch(xx, yy)] = v[4];
				for (auto &it : rot[i]) {
					rot_move(v, it, xx, yy);
					if (!fut[nxtbit].count(ch(xx, yy))) {
						memo[ch(xx, yy)] = v[4];		
					}
				}
				for (auto &it : memo) {
					cost += it.second;
				} 
				chmax(dp[bit], cost);
			}
			return dp[bit];
		};
		cout << dfs((1 << N) - 1) << endl;


	}
}

Measured memory_bytes: 235212
#include<iostream>
#include<climits>
int main()
{
	int imos[100003];
	for(int i = 0; i < 100003; i++)
	{
		imos[i] = 0;
	}
	int N;
	std::cin >> N;
	for(int i = 0; i < N; i++)
	{
		int a, b;
		std::cin >> a >> b;
		imos[a]++;
		imos[b + 1]--;
	}
	for(int i = 0; i < 100002; i++)
	{
		imos[i + 1] += imos[i];
	}
	int ninzu_max = INT_MIN;
	for(int i = 0; i < 100003; i++)
	{
		if(i - 1 <= imos[i])
		{
			ninzu_max = i;
		}
	}
	std::cout << ninzu_max - 1 << std::endl;
	return 0;
}


Measured memory_bytes: 3492
#include<iostream>

using namespace std;

int main(){

	int n;
	int in;
	bool data[10][7]={{0,1,1,1,1,1,1},
					  {0,0,0,0,1,1,0},
	                  {1,0,1,1,0,1,1},
	                  {1,0,0,1,1,1,1},
	                  {1,1,0,0,1,1,0},
	                  {1,1,0,1,1,0,1},
	                  {1,1,1,1,1,0,1},
	                  {0,1,0,0,1,1,1},
	                  {1,1,1,1,1,1,1},
		              {1,1,0,1,1,1,1}};
	bool now[7];

	while(1){

		cin>>n;
		if(n==-1) break;

		for(int i=0;i<7;i++){
			now[i]=false;
		}

		for(int i=0;i<n;i++){
			cin>>in;
			for(int j=0;j<7;j++){
				if(now[j]!=data[in][j]) cout<<"1";
				else cout<<"0";
				now[j]=data[in][j];
			}
			cout<<endl;
		}

	}

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll=unsigned long long;
using ld=long double;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    ll a;
    long double b;
    cin>>a>>b;
    ll ans=a*b;
    cout<<ans<<endl;
}

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

#define ll long long int

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<double> p(n);
    for (ll i = 0; i < n; i++)
    {
        double d;
        scanf("%lf", &d);
        p[i] = d;
    }
    vector<double> dp(n+1);
    dp[0] = 1;
    for (ll i = 0; i < n ; i++) {
        vector<double> dp2(n + 1);
        dp2[0] = (1 - p[i]) * dp[0];
        for (ll j = 1 ; j <= i + 1 ; j++) {
            dp2[j] = (p[i] * dp[j - 1]) + ((1 - p[i]) * dp[j]);
            ll a = 0;
        }
        dp = dp2;
    }

    double an = 0.0;

    for (ll i = n/2 + 1 ; i <= n ; i++) {
        an += dp[i];
    }
    cout << fixed << setprecision(10) << an;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto i = RD;
	
	writeln(N - i + 1);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n),P(n),Q(n);
    for (int i = 0; i < n; ++i) {
        a[i] = i + 1;
    }
    for (int i = 0; i < n; ++i) {
        cin >> P[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> Q[i];
    }
    int cnt = 0;
    int temp1,temp2 = 0;
    do{
        cnt++;
        for (int i = 0; i < n; ++i) {
            if (a[i] != P[i])break;
            if (i == n - 1)temp1 = cnt;
        }
        for (int i = 0; i < n; ++i) {
            if (a[i] != Q[i])break;
            if (i == n - 1)temp2 = cnt;
        }
    } while (next_permutation(a.begin(), a.end()));
    cout << abs(temp1-temp2) << endl;
    return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int a, b, c;
LL ans;

int main(){
	scanf("%d %d %d", &a, &b, &c);
	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0) ans = 0;
	else ans = min(1LL * a * b, min(1LL * b * c, 1LL * a * c));
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


n = int(input())
s, t = input().split()

answer = ""
for ch1, ch2 in zip(s, t):
    answer += ch1 + ch2

print(answer)

Measured memory_bytes: 61916
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let () =
  let a = read_int () in let b = read_int () in
  printf "%s\n" (if (a * b) mod 2 = 0 then "Even" else "Odd")


Measured memory_bytes: 384
//テスト
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;


int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(d,vector<int>(26));
    rep(i,d){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    //答え入れる配列
    vector<int> ans(d);
    //減少
    ll sum=0;
    vector<int> last(26);
    rep(i,d){
        ll nax=-INF;
        ll nax_i;
        rep(j,26){
            ll now_sum=0;
            now_sum+=s[i][j];
            int before_last = last[j];
            last[j]=i+1;
            ll minus=0;
            rep(k,26){
                minus+=c[k]*(i+1-last[k]);
            }
            now_sum-=minus;
            if(nax<now_sum){
                nax_i = j;
                nax = now_sum;
            }
            last[j]=before_last;
        }
        ans[i] = nax_i+1;
    }  
    rep(i,d){
        cout << ans[i] << endl;
    }
	return 0;   
}


Measured memory_bytes: 3664
n = int(input())
x =[]
ch = 1
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    x.append(s)
x.sort()
x.append('X')
for i in range(n):
    if x[i]==x[i+1]:
        ch+=1
    else:
        ans += ch*(ch-1)//2
        ch = 1
print(ans)

Measured memory_bytes: 10612
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

namespace {

int InsertionSort(int* a, int n, int g) {
  int cnt = 0;
  for (int i = g; i < n; ++i) {
    const int v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = v;
  }
  return cnt;
}

int ShellSort(int* a, int n) {
  int cnt = 0;
  int m = 0;
  int G[100];
  G[0] = 1;
  for (int i = 0; i < 100; ++i) {
    G[i + 1] = 3 * G[i] + 1;
    ++m;
    if (G[i + 1] >= n) {
      break;
    }
  }
  sort(G, G + m, greater<int>());

  cout << m << endl;
  for (int i = 0; i < m; ++i) {
    if (i > 0) printf(" ");
    printf("%d", G[i]);
  }
  printf("\n");

  for (int i = 0; i < m; ++i) {
    cnt += InsertionSort(a, n, G[i]);
  }

  return cnt;
}

}  // namespace

int main() {
  int n;
  int a[1000000];

  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  const int cnt = ShellSort(a, n);

  cout << cnt << endl;
  for (int i = 0; i < n; ++i) {
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const ll inf = 1e18;
ll a[maxn],b[maxn],c[maxn];
priority_queue<ll,vector<ll>,greater<ll>>p1,p2;
int main() {
    int X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    for(int i=1; i<=A; i++)
        cin>>a[i];
    for(int i=1; i<=B; i++)
        cin>>b[i];
    for(int i=1; i<=C; i++)
        cin>>c[i];
    sort(a+1,a+1+A,greater<ll>());
    sort(b+1,b+1+B,greater<ll>());
    sort(c+1,c+1+C,greater<ll>());
    ll ans =0;
    for(int i=1; i<=X; i++)
        ans+=a[i],p1.push(a[i]);
    for(int i=1; i<=Y; i++)
        ans+=b[i],p2.push(b[i]);
    for(int i=1; i<=C; i++) {
        ll aa = p1.top();
        ll bb = p2.top();
        if(c[i]>aa&&c[i]>bb) {
            if(aa>bb) {
                ans-=bb;
                p2.pop();
                p2.push(c[i]);
                ans+=c[i];
            } else {
                ans-=aa;
                p1.pop();
                p1.push(c[i]);
                ans+=c[i];
            }
        } else if(c[i]>aa&&c[i]<=bb) {
            ans-=aa;
            p1.pop();
            p1.push(c[i]);
            ans+=c[i];
        } else if(c[i]<=aa&&c[i]>bb) {
            ans-=bb;
            p2.pop();
            p2.push(c[i]);
            ans+=c[i];
        } else if(c[i]<=aa&&c[i]<=bb)
            break;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 5748
A = int(input())
B = int(input())
C = int(input())
X = int(input())
res = 0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
    	if 500 * a + 100 * b + 50 * c == X:
          res += 1
print(res)

Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
ll x1,yy1,x2,yy2;
int N;
vector<pair<ll,ll> >data;
int main(){
	cin>>x1>>yy1>>x2>>yy2;
	ll xsign=1,ysign=1;
	if(x1>x2)xsign=-1;
	if(yy1>yy2)ysign=-1;
	x1*=xsign;
	x2*=xsign;
	yy1*=ysign;
	yy2*=ysign;
	cin>>N;
	rep(i,N){
		ll x,y;
		cin>>x>>y;
		x*=xsign;
		y*=ysign;
		if(x>=x1&&x<=x2&&y>=yy1&&y<=yy2)data.pb(mp(x,y));
	}
	//cout<<data.size()<<endl;
	data.pb(mp(x2,yy2));
	sort(all(data));
	ll dp[214514];
	rep(i,N+2)dp[i]=1e9;
	dp[0]=yy1;
	rep(i,data.size()){
		int ok=0,ng=N+1;
		while(ng-ok>1){
			int mid=(ng+ok)/2;
			if(dp[mid]<=data[i].second){
				ok=mid;
			}else{
				ng=mid;
			}
		}
		dp[ok+1]=data[i].second;
	}
	int len;
	rep(i,N+2)if(dp[i]!=1e9)len=i;
	len--;
	ll mi=min(abs(x1-x2),abs(yy1-yy2))+1;
	long double pi = PI;
	long double ans;
	//cout<<len<<endl;
	if(mi==len){
		//cout<<len<<endl;
		ans = (long double)(((x2-x1)+(yy2-yy1))*100.0)-(long double)((long double)(len-1)*(20.0-5.0*pi)-10.0*pi+20.0);
		
		printf("%.15Lf\n",ans);
	}else{
		//cout<<len<<endl;
		ans = (long double)(((x2-x1)+(yy2-yy1))*100.0)-(long double)(len*(20.0-5.0*pi));
		
		printf("%.15Lf\n",ans);
		
	}
}

Measured memory_bytes: 6512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<algorithm>
using namespace std;
int n,m,T;
#define Maxn 50010
int x[Maxn<<1],y[Maxn<<1];
bitset<Maxn> b[Maxn];
bool ap[Maxn];
int seq[Maxn<<1];
int to[Maxn],B[Maxn];

inline void rd(int &x){
	x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
}

int main(){
	rd(n);rd(m);rd(T);
	for(int i=1;i<=m;++i){
		rd(x[i]);rd(y[i]);
    }
    if(T==1){
		for(int i=1;i<=n;++i)b[i][i]=1;
		bitset<Maxn> res;
		for(int i=m;i>=1;--i){
			res=b[x[i]]|b[y[i]];
			b[x[i]]=b[y[i]]=res;
		}
		res=b[1];
		for(int i=2;i<=n;++i)res&=b[i];
		int flag=-1;
		for(int i=1;i<=n;++i)
		    if(res[i]){
				flag=i;
				break;
		    } 
		if(flag==-1){
			puts("-1");
			return 0;
		}
		ap[flag]=true;
		for(int i=m;i>=1;--i){
			if(ap[x[i]]==false&&ap[y[i]]==false)seq[i]=0;
			else if(ap[x[i]]==true&&ap[y[i]]==true)seq[i]=0;
		    else if(ap[x[i]])seq[i]=0;
		    else seq[i]=1;
		    bool tmp=ap[x[i]]|ap[y[i]];
		    ap[x[i]]=ap[y[i]]=tmp;
		}
		for(int i=1;i<=m;++i)
		    if(seq[i]==0)printf("^");
		    else printf("v");
    }else{
		if(n==2){
			puts("-1");
			return 0;
		}
		for(int i=1;i<=n;++i){
			B[i]=i;
			to[i]=1;
		}
		for(int i=m;i>=1;--i){
			if(B[x[i]]==B[y[i]]){
				seq[i]=0;
				continue;
			}
			if(to[B[x[i]]]>=2){
				seq[i]=1;
				to[B[x[i]]]--;
				B[x[i]]=B[y[i]];
				to[B[y[i]]]++; 
			}else{
				seq[i]=0;
				to[B[y[i]]]--;
				B[y[i]]=B[x[i]];
				to[B[x[i]]]++;
			}
		}
		for(int i=1;i<=m;++i)
		    if(seq[i]==0)printf("^");
		    else printf("v");
    }
    return 0;
}

Measured memory_bytes: 307072
#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define piii pair<pii, int>
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R){int val=rng()%R;assert(val >= 0);return val;}

const long double PI = atan(1.0) * 4;
const int64_t INF64 = 3e18;
const int32_t INF32 = 2e9 + 7;
const int32_t LOG = 21;
const int32_t MOD = MOD1;

using namespace std;


//-------------------DEBUGGING-------------------------
void my_debugger(string s,int LINE_NUM){cerr<<endl;}
template<typename start,typename... end>
void my_debugger(string s,int LINE_NUM,start x,end... y) 
{
    if(s.back()!=',') {s+=',';cerr<<"LINE("<<LINE_NUM<<"): ";}
    int i=s.find(',');
    cerr<<s.substr(0,i)<<" = "<<x;
    s=s.substr(i+1);
    if(!s.empty()) cerr<<", ";
    my_debugger(s,LINE_NUM,y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__,__LINE__,__VA_ARGS__);
#else
#define debug(...) ;
#endif

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



int32_t main()
{
      getFaster;
      //files_init();
      int tests = 1;
      //cin >> tests;
      rep(ii, 0, tests)
      {
            int n;
            cin>>n;
            int a[n][2];
            rep(i,0,n)cin>>a[i][0]>>a[i][1];
            bool g=false;
            rep(i,0,n-2)
            {
                if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1] )
                g=true;
            }
            if(g)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
      }
      return 0;
}


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

void Main()
{
    long n;
    long s = 0;
    cin >> n;
    for(long i=1;i<=n;++i){
        if(!(i % 3 == 0 || i % 5 == 0)){
            s += i;
        }
    }
    cout << s << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n; cin >> n;

    for (int i = 0; i < n; ++i) {
        int u; cin >> u;

        if (u % 2 == 0 && u % 3 != 0 && u % 5 != 0) {
            cout << "DENIED" << endl;
            return 0;
        }
    }

    cout << "APPROVED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BITS(n, num) std::bitset<(n)>((num)).to_string()
#define REV <T> greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll divisor(ll n) {
  ll ret = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret++;
      if (i * i != n)
        ret++;
    }
  }
  return (ret);
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  FOR(b, 1, N + 1) {
    ans += ((N / b) * max(0LL, b - K)) + max(0LL, (N % b) - K + 1);
    if (K == 0)
      ans--;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import math

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

dist = [0 for i in range(n)]
for i in range(n):
    dist[a[i]] += 1
#print(dist)


if (a[0]!=0):
    print(0)
else:
    zero = 0
    for j in range(n):
        if(a[j]==0):
            zero+=1
    #print(zero)
    if(zero==1):
        ans = 1
        now = 1
        total = 1
        while(total<n and now<=n-1):
            for j in range(dist[now]):
                ans *= dist[now-1]
                #print(ans)
                ans %= 998244353
                total+=1
            now+=1
            
        print(ans)
    else:
        print(0)

Measured memory_bytes: 56236
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] ts = new long[n];
        for (int i = 0; i < n; i++) {
            ts[i] = sc.nextLong();
        }
        for(int i = 1; i < n; i++) {
            ts[i] = LCM(ts[i - 1], ts[i]);
        }
        System.out.println(ts[n - 1]);
    }

    static long LCM(long a, long b) {
        return a / GCD(a, b) * b;
    }

    static long GCD(long a, long b) {
        Stack<Pair> stack = new Stack<>();
        stack.push(new Pair(a, b));
        while(!stack.isEmpty()) {
            Pair p = stack.pop();
            if (p.b == 0) {
                return p.a;
            }
            stack.push(new Pair(p.b, p.a % p.b));
        }
        return -1;
    }

    static class Pair {
        long a;
        long b;
        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }
}


Measured memory_bytes: 23380
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_068_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 i      PIC 9(3).
    01 j      PIC 9(3).
    01 N      PIC 9(3).
    01 t      PIC 9(3).
    01 tmp    PIC 9(3).

    01 R      PIC 9(3).

    01 mxt    PIC 9(3).
    01 mxv    PIC 9(3).
    01 ans    PIC X(18).

    01 ZS     PIC Z(4).
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.

    MOVE 1 TO mxv.
    MOVE 0 TO mxt.

    PERFORM VARYING i FROM 2 BY 1 UNTIL N < i
        MOVE 0 TO t
        MOVE i TO tmp

        PERFORM VARYING j FROM 1 BY 1 UNTIL tmp = 0
            ADD 1 TO t
            DIVIDE 2 INTO tmp GIVING tmp REMAINDER R
            IF R = 1 THEN
                EXIT PERFORM
            END-IF
        END-PERFORM

        IF mxt < t THEN
            MOVE i TO mxv
            MOVE t TO mxt
        END-IF
    END-PERFORM.

    MOVE mxv TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

int main(int argc, char **argv)
{
	ll n, k; cin >> n >> k;
	map<ll, ll> m;

	for (int i = 0; i < n; ++i)
	{
		ll a, b; cin >> a >> b;
		if (m.count(a) == 0)
			m[a] = b;
		else
			m[a] += b;
	}

	ll ans;
	for (auto &e : m)
	{
		k -= e.second;
		if (k <= 0)
		{
			ans = e.first;
			break;
		}
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  for(int i=0;i<3;i++){
    if(n.at(i)=='1'){
      n.at(i)='9';
    }
    else {
      n.at(i)='1';
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	char a, b; cin >> a >> b;
	if(a == 'H' && b == 'H') printf("H\n");
	else if(a == 'H' && b == 'D') printf("D\n");
	else if(a == 'D' && b == 'H') printf("D\n");
	else printf("H\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d", &N);
	int A[100];
	
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	int max[10000];
	int Max = A[0]-A[1];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			max[i] = A[i]-A[j];
			if(Max < max[i]){
				Max = max[i];
			}
		}
	}
	printf("%d\n", Max);
	return 0;
}


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

int main()
{
	double s, sum;

	while (cin >> s){
		s *= 3;
		sum = s;
		for (int i = 0; i < 4; i++){
			s *= 2.0 / 3.0;
			sum += s;
		}
		printf("%.7lf\n", sum);
	}
	return (0);
}

Measured memory_bytes: 1236
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "begin", long, "end");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto h = aryread();
    foreach_reverse (i; iota(1, n))
    {
        if (h[i - 1] > h[i])
        {
            h[i - 1]--;
        }
        if(h[i - 1] > h[i])
        {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 5944
#include <iostream>

int main(int argc, char const* argv[]) {
	int x,y;
	std::cin >> x >> y;
	while (!(x==y&&x==0)) {
		if (x <= y) {
			std::cout << x << " " << y << std::endl;
		} else {
			std::cout << y << " " << x << std::endl;
		}
		std::cin >> x >> y;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <cstdio>

#define Maxn 200010

using namespace std;

inline int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int n, k, a[Maxn], mark[Maxn];

int main() {
    n = read(); k = read();
    for(int i = 1; i <= n; ++i) a[i] = read();
    for(int t = 1; t <= k; ++t) {
        memset(mark, 0, sizeof(mark));
        for(int i = 1; i <= n; ++i) {
            int l = max(1, i - a[i]), r = min(n, i + a[i]);
            ++mark[l]; --mark[r + 1];
        }
        int sum = 0; bool flag = 1;
        for(int i = 1; i <= n; ++i) {
            sum += mark[i];
            a[i] = sum;
            if(a[i] != n) flag = 0;
        }
        if(flag) break;
    }
    for(int i = 1; i <= n; ++i) printf("%d ", a[i]);
    cout << endl;
    return 0;
}

Measured memory_bytes: 5272
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n,k;
vector<int> g[100010];
bool used[100010];

int ans = 1;
const int mod = 1000000007;

void dfs(int v, int m){
    used[v]=true;
    ans=(ans*m)%mod;
    chmax(m,k-1);
    for(int i:g[v]){
        if(!used[i])dfs(i,--m);
    }
}

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

    cin>>n>>k;
    rep(i,n-1){
        int a,b; cin>>a>>b; a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }

    dfs(0,k);
    cout<<ans<<endl;

}

Measured memory_bytes: 8192
#include<cstdio>
typedef long long LL;
const int N=1e6+5,md=998244353,iv2=(md+1)/2;
int fac[N],iv[N],n,m,ans;
inline int pow(int a,int b){
	int ret=1;
	for(;b;b>>=1,a=(LL)a*a%md)if(b&1)ret=(LL)ret*a%md;
	return ret;
}
inline int C(int n,int m){return(LL)fac[n]*iv[m]%md*iv[n-m]%md;}
inline int iC(int n,int m){return(LL)iv[n]*fac[m]%md*fac[n-m]%md;}
int main(){
	scanf("%d%d",&n,&m);
	if(n<m)n^=m^=n^=m;
	for(int i=*fac=1;i<=n+m;++i)fac[i]=(LL)fac[i-1]*i%md;
	iv[n+m]=pow(fac[n+m],md-2);
	for(int i=n+m-1;~i;--i)iv[i]=(i+1LL)*iv[i+1]%md;
	for(int i=1;i<=m;++i)
	ans=(ans+(LL)C(i+i,i)*C(n+m-2*i,n-i))%md;
	ans=(ans*(LL)iv2%md*iC(n+m,n)+n)%md;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int H,W;
    map<int,int>m;
    map<int,int>n;
    cin >> H >> W;
    char a[H][W];
    
    int x[W],y[H];
    
    for(int i = 0; i < W; i++) {
         
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(a[i][j] == '.' ) {
                m[i]++;
            }
        }
        if(m[i] == W) {
            y[i] = 1;
        }
    }
    
    for(int i = 0; i < W; i++) {
        for(int j = 0; j < H; j++) {
            if(a[j][i] == '.' ) {
                n[i]++;
            }
        }
        if(n[i] == H) {
            x[i] = 1;
        }
    }

    for(int i = 0; i < H; i++) {
        if(y[i] != 1) {
            for(int j = 0; j < W; j++) {
                if(x[j] != 1) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    ll T;
    cin >> n >>T;
    vector<ll> t(n);
    rep(i,n) cin >> t[i];
    
    ll ans_time = T;
    rep(i,n-1){
        ans_time += min(T,t[i+1] - t[i]);
    }
    cout << ans_time <<endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;
public class Main{
		public static void main(String[] args){
		long PRIME=1000000007;
		Scanner sc=new Scanner(System.in);
		int N =Integer.parseInt(sc.next());
		int M =Integer.parseInt(sc.next());
		long[] x= new long[N];
		long[] y= new long[M];
		for(int i=0;i<N;i++)x[i]=Long.parseLong(sc.next());
		for(int j=0;j<M;j++)y[j]=Long.parseLong(sc.next());
		Arrays.sort(x);
		Arrays.sort(y);
		long xans =0;
		long yans =0;
		for(int i=0;i<N;i++){
			xans=(xans+(i-(N-1-i))*x[i])%PRIME;
		}
		for(int j=0;j<M;j++){
			yans=(yans+(j-(M-1-j))*y[j])%PRIME;
		}
		System.out.println((xans*yans)%PRIME);
		sc.close();
	}
}

Measured memory_bytes: 52296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
bool ch(string s) {
	ll l = 0;
	ll r = sz(s) - 1;
	while (l <= r) {
		if (s[l] == s[r]) {
			l++, r--;
		}	
		else {
			break;
		}
	}
	if (l <= r) return false;
	else return true; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	string s;
 	cin >> s;
 	ll len = sz(s) / 2;
 	string s1 = s.substr(0, len);
 	string s2 = s.substr(len + 1, len);
 	if (ch(s) && ch(s1) && ch(s2)) {
 		cout << "Yes" << endl;
 	}   
 	else {
 		cout << "No" << endl;
 	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 200000;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;

struct State {
	pair<ll, int> normal, root;
	State(){}
	State(ll a, int b, ll c, int d) {
		normal = make_pair(a, b);
		root = make_pair(c, d);
	}
};

int N;
ll X[Maxn + 5];
vector<pair<int, int> > G[Maxn + 5];
inline void addedge(int u, int v, int w) {
	G[u].push_back(make_pair(v, w));
	G[v].push_back(make_pair(u, w));
}

int fa[Maxn + 5];
int find(int x) {
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}
bool unite(int u, int v) {
	int fu = find(u), fv = find(v);
	if(fu == fv) return false;
	fa[fu] = fv;
	return true;
}

int belong[Maxn + 5];

State f[Maxn + 5];
State min(State lhs, State rhs) {
	if(rhs.normal.first < lhs.normal.first) {
		if(rhs.normal.second != lhs.normal.second)
			lhs.root = lhs.normal;
		lhs.normal = rhs.normal;
		if(rhs.root.first < lhs.root.first)
			lhs.root = rhs.root;
	} else {
		if(rhs.normal.second != lhs.normal.second) {
			if(rhs.normal.first < lhs.root.first)
				lhs.root = rhs.normal;
		} else if(rhs.root.first < lhs.root.first)
			lhs.root = rhs.root;
	}
	return lhs;
}
void DFS1(int u, int fa) {
	f[u] = State(X[u], belong[u], INFLL, -1);
	for(int i = 0; i < (int)G[u].size(); i++) {
		int v = G[u][i].first, w = G[u][i].second;
		if(v == fa) continue;
		DFS1(v, u);
		State tmp = f[v];
		tmp.normal.first += w, tmp.root.first += w;
		f[u] = min(f[u], tmp);
	}
}
void DFS2(int u, int fa, State last) {
	f[u] = min(f[u], last);
	for(int i = 0; i < (int)G[u].size(); i++) {
		int v = G[u][i].first, w = G[u][i].second;
		if(v == fa) continue;
		State tmp = f[u];
		tmp.normal.first += w, tmp.root.first += w;
		DFS2(v, u, tmp);
	}
}

pair<ll, int> mn[Maxn + 5];
int rts[Maxn + 5];
int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
		scanf("%lld", &X[i]);
	for(int i = 1; i <= N; i++) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		addedge(u, v, w);
	}
	for(int i = 1; i <= N; i++)
		fa[i] = i;
	ll ans = 0;
	while(true) {
		int cnt = 0;
		for(int i = 1; i <= N; i++)
			if(fa[i] == i) {
				belong[i] = ++cnt;
				rts[belong[i]] = i;
			}
		if(cnt == 1) break;
		for(int i = 1; i <= N; i++)
			belong[i] = belong[find(i)];
		DFS1(1, 0), DFS2(1, 0, State(INFLL, -1, INFLL, -1));
		for(int i = 1; i <= cnt; i++)
			mn[i] = make_pair(INFLL, -1);
		for(int i = 1; i <= N; i++) {
			if(f[i].normal.second == belong[i])
				mn[belong[i]] = min(mn[belong[i]], make_pair(f[i].root.first + X[i], f[i].root.second));
			else mn[belong[i]] = min(mn[belong[i]], make_pair(f[i].normal.first + X[i], f[i].normal.second));
		}
		for(int i = 1; i <= cnt; i++)
			if(unite(rts[i], rts[mn[i].second]))
				ans += mn[i].first;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 52608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100100;
int n, h[N];
int memo[N];
int dp(int i){
    if(i >= n){
        return 1e9;
    }
    if(i == n-1){
        return 0;
    }
    int &ret = memo[i];
    if(ret != -1)
        return ret;
    int path1, path2;
    path1 =  dp(i+1) + abs(h[i] - h[i+1]);
    path2 =  dp(i+2) + abs(h[i] - h[i+2]);

    return ret = min(path1, path2);
}
int main(){
    memset(memo, -1, sizeof memo);
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &h[i]);
    printf("%d", dp(0));
    return 0;
}


Measured memory_bytes: 4096
// Problem : E - Knapsack 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 105
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int mp[105][100005];
int n,w;
pp arr[maxn];
int fun(int l,int wt)
{
	if(l == 0 || wt == 0)
		return 0;
	if(mp[l][wt]!=-1)
		return mp[l][wt];
	int x=0;
	if(arr[l].ff <= wt)	
		x = arr[l].ss + fun(l-1,wt-arr[l].ff);
	x = max(x,fun(l-1,wt));
	mp[l][wt]=x;
	return x;
}
void solve()
{
	memset(mp,-1,sizeof(mp));
	cin >> n >> w;
	repe(i,1,n)
	{
		int x,y;
		cin >> x >> y;
		arr[i]={x,y};
	}
	cout << fun(n,w);
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 85664
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Nm = N % 10;
        
        String ans = "hon";
        if(Nm == 3) {
            ans = "bon";
        } else if(Nm == 0 || Nm == 1 || Nm == 6 || Nm == 8) {
            ans = "pon";
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 35588
#include <stdio.h>

int main() {
  int x,a,b;
  int jarak1,jarak2;
  scanf("%d %d %d",&x,&a,&b);
  jarak1 = x-a;
  jarak2 = x-b;
  if (jarak1<0){
  		jarak1 *= -1;
  }
  if (jarak2<0){
  		jarak2 *= -1;
  }
  if (jarak1<jarak2){
  		printf("A");
  }
  else{
  		printf("B");
  }
  return 0;
}

Measured memory_bytes: 1620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#include<queue>
using namespace std;
int main() {
	string s;
	int g = 0, p = 0, score1 = 0, score2 = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'p') {
			score1--;
			g++;
		}
		else if (s[i] == 'g' && p < g) {
			score1++;
			p++;
		}
		else g++;
	}
	g = 0; p = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'p'&& p < g)p++;
		else if (s[i] == 'g' && p < g) {
			score2++;
			p++;
		}
		else if(s[i]=='p'){
			score2--;
			g++;
		}
		else g++;
	}
	cout << max(score1,score2) << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll x,k,d;
	cin>>x>>k>>d;
	if(x<0)
	{
		x=-x;
	}
	ll val=x/d,rem=x%d;
	if(abs(val)>k)
	{
		x=x-k*d;
	}
	else if(abs(val)==k)
	{
		x=x-k*d;
	}
	else
	{
		if(k%2==val%2)
		{
			x=x-val*d;
		}
		else
		{
			x=x-val*d-d;
		}
	}
	cout<<abs(x);
	return 0;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String a = in.readLine();
    String b = in.readLine();
    String ans = "123";
    System.out.println((ans.replace(a,"")).replace(b,""));
  }
}

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

#define DBG(x) ;//cerr << #x << " = " << x << endl

int N,M;
int s[234567],t[234567];
vector<int>G[234567];
vector<pair<int,int>>nG[234567];//bridge:positive,others:0
vector<int>pG[234567];//forest

int af[234567];
int dpar[234567];
vector<int>dch[234567];
int imos[234567];
bool dok[234567];
int cntcnt = 0;
void dfs1(int x){
	af[x] = cntcnt;
	++cntcnt;
	for(int ch:G[x]){
		if(af[ch]<0){
			dpar[ch]=x;
			dfs1(ch);
		}
	}
}
int dfs2(int x){
	//cerr<<x<<"!!!!!!!!!!!!!"<<endl;
	for(int ch:dch[x]){
		//cerr<<ch<<"<-----"<<x<<endl;
		//if(dpar[ch]==x){
			imos[x]+=dfs2(ch);
		//}
	}
	DBG(x);
	DBG(imos[x]);
	return imos[x];
}

int id[234567];
int idcnt[234567];
void dfs3(int x,int ls,int nid){
	id[x]=nid;
	for(auto pp:nG[x]){
		if(pp.second!=0)continue;
		int ch = pp.first;
		if(ch!=ls){
			if(id[ch] < 0){
				dfs3(ch,x,nid);
			}
		}
	}
}

int memo[234567][2];
int dp(int x,int k,int ls=-1){
	if(k==-1)return max(dp(x,0,ls),dp(x,1,ls));
	if(memo[x][k]>=0)return memo[x][k];
	int res = k ? idcnt[x] : 0;
	if(k){
		for(int ch:pG[x]){
			if(ch!=ls){
				res+=dp(ch,0,x);
			}
		}
	}else{
		for(int ch:pG[x]){
			if(ch!=ls){
				res+=dp(ch,-1,x);
			}
		}
	}
	return memo[x][k]=res;
}

int main(){
	cin>>N>>M;
	for(int j=0;j<M;++j){
		cin>>s[j]>>t[j];
		G[s[j]].push_back(t[j]);
		G[t[j]].push_back(s[j]);
	}
	fill(af,af+N,-1);
	fill(dpar,dpar+N,-1);
	for(int i=0;i<N;++i){
		if(dpar[i]<0){
			dok[i]=true;
			dfs1(i);
		}
	}
	for(int i=0;i<N;++i){
		if(dpar[i]>=0){
			dch[dpar[i]].push_back(i);
			//cerr<<dpar[i]<<"<====="<<i<<endl;
		}
	}
	for(int j=0;j<M;++j){
		int ss=s[j],tt=t[j];
		if(dpar[ss]==tt){
			swap(ss,tt);
		}
		if(dpar[tt]!=ss){
			int from = (af[ss]<af[tt])?tt:ss;
			int to = (af[ss]<af[tt])?ss:tt;
			imos[from]++;
			imos[to]--;
		}
	}
	for(int i=0;i<N;++i){
		if(dok[i])
			dfs2(i);
	}
	set<pair<int,int>>bridge;
	for(int i=0;i<N;++i){
		if(!dok[i]&&imos[i]==0){
			bridge.insert({i,dpar[i]});
			DBG(i);
			DBG(dpar[i]);
		}
	}
	for(int j=0;j<M;++j){
		int nowc = bridge.count({s[j],t[j]}) + bridge.count({t[j],s[j]});
		nG[s[j]].push_back({t[j],nowc});
		nG[t[j]].push_back({s[j],nowc});
	}
	fill(id,id+N,-1);
	for(int i=0;i<N;++i){
		if(id[i]<0){
			dfs3(i,-1,i);
		}
	}
	for(int i=0;i<N;++i){
		idcnt[id[i]]++;
		DBG(id[i]);
	}
	for(auto p : bridge){
		DBG(p.first);
		DBG(p.second);
		int ss = id[p.first];
		int tt = id[p.second];
		pG[ss].push_back(tt);
		pG[tt].push_back(ss);
		DBG(ss);
		DBG(tt);
	}
	int ans = 0;
	memset(memo,0xff,sizeof(memo));
	for(int i=0;i<N;++i){
		if(dok[i]){
			ans += dp(id[i],-1);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 46232
#include <cstdio>

char a[101][101];

int main() {
  int i, j, A, B;
  scanf("%d%d", &A, &B);
  for (i = 0; i < 50; i++) for (j = 0; j < 100; j++) {
    a[i][j] = '#';
    a[i + 50][j] = '.';
  }
  for (i = 0; i + 1 < A; i++) a[i / 50 * 2][i % 50 * 2] = '.';
  for (i = 0; i + 1 < B; i++) a[99 - i / 50 * 2][i % 50 * 2] = '#';
  puts("100 100");
  for (i = 0; i < 100; i++) puts(a[i]);
}

Measured memory_bytes: 128