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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define SI(v) static_cast<int>(v.size())

int n, m, a[300][300];
vector<pair<int, int>> v[300];
bool f[300];

int main() {
	cin >> n >> m;
	inc(i, n) {
	inc(j, m) {
		cin >> a[i][j];
		a[i][j]--;
	}
	}
	
	inc(i, n) { v[a[i][0]].EB(i, 0); }
	inc(k, m) { f[k] = true; }
	
	int ans = n;
	inc(q, m) {
		auto p = MP(-1, -1);
		inc(k, m) { setmax(p, MP(SI(v[k]), k)); }
		setmin(ans, p.FI);
		
		if(q == m - 1) { break; }
		
		for(auto && e: v[p.SE]) {
			int i = e.FI;
			int j = e.SE;
			incID(jj, j + 1, m) { if(f[a[i][jj]]) { j = jj; break; } }
			v[a[i][j]].EB(i, j);
		}
		v[p.SE].clear();
		f[p.SE] = false;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void) {
	int A, B, C, D;
	scanf("%d%d%d%d", & A, & B, & C, & D);

	for (int i = 1; i <= A + D; i += 0) {
		C -= B;
		if (C <= 0) {
			printf("Yes");
			return 0;
		}
		A -= D;
		if (A <= 0) {
			printf("No");
			return 0;
		}
	}
}

Measured memory_bytes: 1736
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	H := getInt()
	N := getInt()
	
	sum := 0
	for i := 0; i < N; i++ {
		sum += getInt()
	}
	
	if H <= sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    int res = 0;
    int min_diff = 0x3f3f3f3f;
    int min_value = 0;
    for (int i = 1; i <= n; i++) {
        int t = l + i - 1;
        if (abs(t) < min_diff) {
            min_diff = abs(t);
            min_value = t;
        }
        res += t;
    }
    cout << res - min_value << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<algorithm>
#include<bitset>
#include<utility>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
string s;
typedef long long ll;
const ll MOD=1e9+7;
ll dp[2],ans=0,num[100004],q=0;
int main()
{
	num[0]=1;
	for (int i=1;i<=1e5;i++)
		num[i]=num[i-1]*3%MOD;
	cin>>s;
	for (int i=0;i<s.size();i++)
	{
		if (s[i]=='A')
			dp[0]=(dp[0]+num[q])%MOD;
		if (s[i]=='B')
			dp[1]=(dp[1]+dp[0])%MOD;
		if (s[i]=='C')
			ans=(ans+dp[1])%MOD; 
		if (s[i]=='?')
		{
			ans=(ans*3+dp[1])%MOD;
			dp[1]=(dp[1]*3+dp[0])%MOD;
			dp[0]=(dp[0]*3+num[q])%MOD;
			q++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

#define ll long long

const int maxn = 135000;

int n;
int color[maxn],ind[maxn];
int vis[maxn];

vector<pair<int,ll> >G[maxn];

void dfs(int u,ll dist,int mark,int f){
    if(dist%2==0)color[u]=mark;
    if(vis[u])return ;
    vis[u]=1;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        ll d=G[u][i].second;
        if(v==f)continue;
        dfs(v,dist+d,mark,u);
    }
}

int main(){
    cin>>n;
    FOR(i,1,n-1){
        int u,v;
        ll w;
        scanf("%d%d%lld",&u,&v,&w);
        G[u].push_back(make_pair(v,w));
        G[v].push_back(make_pair(u,w));
        ind[u]++,ind[v]++;
        //cout<<u<<":"<<ind[u]<<" "<<v<<":"<<ind[v]<<endl;
    }
    int root;
    FOR(i,1,n)if(ind[i]==1)root=i;
    dfs(root,0,1,-1);
    FOR(i,1,n){
        printf("%d\n",color[i]);
    }
}


Measured memory_bytes: 16512
#include<stdio.h>
#include<math.h>
#include <string.h>

int main() {
	int i, j, k, l = 0;
	int m, g, n, q;
	long long int f;
	long long int h;


	scanf("%lld", &h);


	for (i = 0;h > 1;i++) {
		h = h / 2;
	}
	
	f = exp2(i+1)-1;

	printf("%lld", f);


	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    int N, L;
    cin >> N >> L;

    int R = L + N - 1;

    int res;
    if (L <= 0 && 0 <= R) {
        res = (L + R) * (R - L + 1) / 2;
    } else if (R <= 0) {
        R--;
        res = (L + R) * (R - L + 1) / 2;
    } else {
        L++;
        res = (L + R) * (R - L + 1) / 2;
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
S,ans=0,0
for a,b in zip(A,B):
    if a>=b:C.append(a-b)
    else:
        ans +=1
        S +=b-a
C.sort()
while S>0 and C:
    ans +=1
    S -=C.pop()
print(-1 if S>0 else ans)

Measured memory_bytes: 19052
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,r;
    while(scanf("%d %d",&n,&r),n!=0) {
        vector<int> v;
        for(int i=n;i>=1;i--) v.push_back(i);
        for(int i=0;i<r;i++) {
            vector<int> nv;
            int p,c;
            scanf("%d %d",&p,&c);p--;
            for(int i=0;i<c;i++) {
                nv.push_back(v[p+i]);
            }
            for(int i=0;i<p;i++) nv.push_back(v[i]);
            for(int i=p+c;i<n;i++) nv.push_back(v[i]);
            v=nv;
        }
        printf("%d\n",v[0]);
    }
}

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

typedef long long ll;
typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =100000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

ll MOD = 1e9 + 7;

void solve() {
    ll m, s, t;
    cin >> V >> m >> s >> t;
    vector<ll> u(m), v(m), a(m), b(m);
    rep(i,m) {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        G[u[i] - 1].push_back({v[i] - 1, a[i]});
        G[v[i] - 1].push_back({u[i] - 1, a[i]});
    }
    dijkstra(s - 1);
    vector<ll> ds(V);
    rep(i,V) ds[i] = d[i];
    //rep(i,V) cout << i << " " << ds[i] << endl;
    rep(i,m) G[i] = {};
    rep(i,m) {
        G[u[i] - 1].push_back({v[i] - 1, b[i]});
        G[v[i] - 1].push_back({u[i] - 1, b[i]});
    }
    dijkstra(t - 1);
    //rep(i,V) cout << i << " " << d[i] << endl;
    vector<P> dst(V);
    rep(i,V) dst[i] = P(d[i] + ds[i], i);
    sort(dst.begin(), dst.end());
    //rep(i,V) cout << i << " " << dst[i].first << " " << dst[i].second << endl;
    int change = 0;
    ll money = 1e15;
    rep(i, V) {
        while (dst[change].second < i) change++;
        cout << money - dst[change].first << endl;
    }
    return;
}

int main() {
    solve();
}


Measured memory_bytes: 15616
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]

S=input()

if S[3]==S[2] and S[5]==S[4]:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 38512
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;

int n;
int h[N];
int dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  dp[1] = abs(h[1]-h[0]);
  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]));
  }
  cout << dp[n-1] << nl;
  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int a;
	scanf("%d", &a);
	for (int i = 0; i < a;i++) {
		int b, c, d;
		scanf("%d%d%d", &b, &c, &d);
		int max = b;
		if (b<c)max = c;
		if (max<d)max = d;
		if (max*max == b*b + c*c + d*d - max*max)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  int n;
  cin >> n;
  int b[n - 1];
  inputArray(b,n - 1);
  int ans = 0;
  rep(i,n - 1)
  {
    if(i > 0)
    {
      if(b[i] > b[i - 1])
      {
        ans += b[i - 1];
      }
      else
      {
        ans += b[i];
      }
    }
    else if(i == 0)
    {
      ans+=b[i];
    }
    if(i == n - 2) 
    {
      ans+=b[i];
    }
  }
  cout << ans << endl;
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Tree{
  Tree *left, *right;
  int32_t *key;
  Tree(): left(nullptr), right(nullptr), key(nullptr){}
  Tree* xfind(int32_t x){
    if(Tree::key==nullptr) return this;
    if(x<*Tree::key){
      if(Tree::left==nullptr) Tree::left=new Tree;
      return Tree::left->xfind(x);
    } else if(x>*Tree::key){
      if(Tree::right==nullptr) Tree::right=new Tree;
      return Tree::right->xfind(x);
    } else{
      return this;
    }
  }
  void insert(int32_t x){
    Tree* tmp=Tree::xfind(x);
    if(tmp->key==nullptr) tmp->key=new int32_t(x);
  }
  bool find(int32_t x){
    Tree* tmp=Tree::xfind(x);
    if(tmp->key!=nullptr&&*(tmp->key)==x) return true;
    else return false;
  }
  Tree* xinorder(){
    if(Tree::left!=nullptr&&Tree::left->key!=nullptr) return Tree::left->xinorder();
    else return this;
  }
  void xdelete(){
    // cout<<*Tree::key<<endl;
    delete Tree::key;
    if(Tree::left!=nullptr&&Tree::left->key==nullptr){
      delete Tree::left; Tree::left=nullptr;
    }
    if(Tree::right!=nullptr&&Tree::right->key==nullptr){
      delete Tree::right; Tree::right=nullptr;
    }
    if(Tree::left==nullptr){
      if(Tree::right==nullptr){
        Tree::key=nullptr;
      }
      else{
        Tree::key=Tree::right->key;
        Tree::left=Tree::right->left;
        Tree::right=Tree::right->right;
      }
    } else{
      if(Tree::right==nullptr){
        Tree::key=Tree::left->key;
        Tree::right=Tree::left->right;
        Tree::left=Tree::left->left;
      } else{
        Tree* tmp=Tree::right->xinorder();
        Tree::key=new int32_t(*(tmp->key));
        tmp->xdelete();
      }
    }
  }
  void delete1(int32_t x){
    Tree* tmp=Tree::xfind(x);
    if(tmp->key!=nullptr&&*(tmp->key)==x) tmp->xdelete();
  }
  void preorder(){
    if(Tree::key!=nullptr){
      cout<<' '<<*Tree::key;
      if(Tree::left!=nullptr) Tree::left->preorder();
      if(Tree::right!=nullptr) Tree::right->preorder();
    }
  }
  void inorder(){
    if(Tree::key!=nullptr){
      if(Tree::left!=nullptr) Tree::left->inorder();
      cout<<' '<<*Tree::key;
      if(Tree::right!=nullptr) Tree::right->inorder();
    }
  }
  void postorder(){
    if(Tree::key!=nullptr){
      if(Tree::left!=nullptr) Tree::left->postorder();
      if(Tree::right!=nullptr) Tree::right->postorder();
      cout<<' '<<*Tree::key;
    }
  }
};

int32_t main(){
  size_t n; cin>>n;
  Tree tree;
  string cmd;
  int32_t key;
  for(int i=0; i<n; ++i){
    cin>>cmd;
    switch(cmd[0]){
      case 'i': cin>>key; tree.insert(key); break;
      case 'f': cin>>key; cout<<(tree.find(key)?"yes\n":"no\n"); break;
      case 'd': cin>>key; tree.delete1(key); break;
      default: tree.inorder(); cout<<'\n'; tree.preorder(); cout<<'\n';
    }
  }
}


Measured memory_bytes: 28628
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<vector<P>> g;

int main() {
    
    
    ll n;
    cin >> n;
    
    vector<ll> num1;
    vector<ll> num2;
    
    ll ret = 0;
    
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            if (i != 1)
            {
                num1.push_back(i);
            }
            if (n != i * i)
            {
                num1.push_back(n / i);
            }
        }
    }
    
    for (ll i = 1; i * i <= n; ++i)
    {
        if ((n - 1ll) % i == 0)
        {
            if (i != 1)
            {
                num2.push_back(i);
            }
            if (n - 1ll != i * i)
            {
                num2.push_back((n - 1ll) / i);
            }
        }
    }
    
    for (int i = 0; i < num1.size(); ++i)
    {
        ll tmp = n;
        while (1)
        {
            if (tmp % num1[i] == 0)
            {
                tmp /= num1[i];
                continue;
            }
            tmp = tmp - ((tmp / num1[i]) * num1[i]);
            break;
        }
        if (tmp == 1)
        {
            ret++;
        }
    }
    
    for (int i = 0; i < num2.size(); ++i)
    {
        ll tmp = n;
        if (tmp % num2[i] != 0)
        {
            ret++;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

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

#define rep(i,j) for(int i=0;i<(j);i++)
using namespace std;;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define X first
#define Y second
#define fs first
#define sc second
#define pb push_back
#define em emplace_back

#define rrep(X,Y) for(int (X)=(Y)-1; X >= 0; --(X))
typedef long long ll;

struct UF{
  vector<int> data;
  UF (int size) : data(size, -1){}
  bool unite(int x,int y){
    //cout<<"unite"<<x<<","<<y<<endl;
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x])swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x){return -data[root(x)];}
};

typedef vector<vector<pii>> Graph;

template<class T> ostream & operator<< (ostream & os,const vector<T> &t){
  os<<"{";for(auto a:t)os<<a<<",";os<<"}"<<endl;
  return os;
}

int main(){
  int n,m;
  while(cin>>n>>m&&n){
    map<int,vi> mp;
    vector<int> hs(n);
    rep(i,n){
      cin >> hs[i];
      mp[-hs[i]].pb(i);
    }
    Graph g(n);
    rep(i,m){
      int a,b,c;
      cin >> a >> b >> c;
      a--;
      b--;
      if(hs[a]>=hs[b])
	g[b].emplace_back(a,c);
      if(hs[b]>=hs[a])
	g[a].emplace_back(b,c);
    }
    UF uf(n);
    vector<int> tree(mp.size(),1);
    int i=0;
    set<int> ex;
    UF tr(n);
    for(const auto &p:mp){
      for(int d:p.Y){
	for(pii v:g[d])
	  tr.unite(v.X,d);
	ex.insert(d);
      }
      //if(i==1)cout<<tr.data;
      for(int v:ex)
	if(!tr.same(*ex.begin(),v))tree[i]=0;
      ++i;
    }
    //cout<<tree;
    rrep(i,mp.size())if(i)
      tree[i-1]&=tree[i];
    priority_queue<pair<int,pii>> que;
    ll re=0,temp;
    i=0;
    //cout<<tree;
    for(const auto &p:mp){
      for(int d:p.Y){
	for(pii v:g[d])
	  que.emplace(-v.Y,pii(d,v.X));
	ex.insert(d);
      }
      if(!tree[i++])continue;
      //ダルダルダルメシアン
      //cout<<p.Y<<endl;
      while(!que.empty()){
	auto p=que.top(); que.pop();
	if(!uf.same(p.Y.X,p.Y.Y)){
	  re-=p.X;
	  uf.unite(p.Y.X,p.Y.Y);
	}
      }
    }
    cout << re << endl;
  }
  return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
//const int MOD = (int)1e9 + 7;
const int MOD = 998244353;

const double EPS = 1e-9;

int modpow(int x, int n, const int mo) {
	int res = 1;
	while (n > 0) {
		if (n & 1) (res *= x) %= mo;
		(x *= x) %= mo;
		n >>= 1;
	}
	return res;
}

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

	int N;
	cin >> N;
	vector<int> CNT(N, 0);

	int A;
	bool ok = true;
	rep(i, 0, N)
	{
		cin >> A;
		if (i == 0 && A != 0)ok = false;
		CNT[A]++;
	}

	if (!ok||CNT[0] != 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int sum = 0;
	int ans = 1;
	rep(i, 0, N)
	{
		if (i>0&&sum < N)
		{
			ans *= modpow(CNT[i - 1], CNT[i], MOD);
			ans %= MOD;
		}
		sum += CNT[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3972
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = Input.nextInt();
        int y = Input.nextInt();
        int a = 0;
        int b = 0;
        int c = y / 1000;
        if (c < n)
        {
            Console.WriteLine("-1 -1 -1");
            return;
        }
        while (n + 4 <= b + c&&c>=5)
        {
            b++;
            c -= 5;
        }
        if (b + c == n)
        {
            Console.WriteLine("0 " + b + " " + c);
            return;
        }
        while (n < a + b + c && b >= 2)
        {
            b -= 2;
            a++;
        }
        if (a + b + c == n)
        {
            Console.WriteLine(a + " " + b + " " + c);
        }
        else
        {
            Console.WriteLine("-1 -1 -1");
        }
    
    }

    class Input
    {
        static string[] line = { };
        static int index = 0;
        static void readLine()
        {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        public static int nextInt()
        {
            if (index == line.Length)
            {

                readLine();
            }
            index++;
            return int.Parse(line[index - 1]);
        }
        public static long nextLong()
        {
            if (index == line.Length)
            {

                readLine();
            }
            index++;
            return long.Parse(line[index - 1]);
        }
        public static string next()
        {
            if (index == line.Length)
            {

                readLine();
            }
            index++;
            return line[index - 1];
        }
    }
}



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

int main() {
  int a,b;
  cin >> a >> b;
  if(a<b)
    cout << "a < b" << endl;
  else if(a>b)
    cout << "a > b" << endl;
  else if(a==b)
    cout << "a == b" << endl;
}


Measured memory_bytes: 3100
def main():
    n = int(input())
    ss = list(input())
    num_sum = [0]*n
    west_sum = 0
    east_sum = 0
    for i in range(1, n):
        if ss[i-1] == 'W':
            west_sum += 1
        num_sum[i] += west_sum

    for i in range(n-2, -1, -1):
        if ss[i+1] == 'E':
            east_sum += 1
        num_sum[i] += east_sum

    ans = min(num_sum)
    print(ans)

if __name__ == "__main__":
    main()


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

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

typedef long long ll;
typedef pair<int, int> P;

#define INF 1e9

int main(int, char**)
{
  int n;
  ll d;
  cin >> n >> d;

  int ans = 0;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main(void)
{
    // コンテスト参加回数が N で表示レーティングが R 
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    }
    else {
        cout << R + (100 * (10 - N)) << endl;
    }
}


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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==m)
     cout<<"Yes\n";
     else
      cout<<"No\n";
      return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}
ll a;
int main(){
	//freopen("in.txt","r",stdin);
	cin>>a;
	o(3LL*a*a);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        for (int i = 0; i < 10; i++) {
            x = r * x - d;
            System.out.println(x);
        }

    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
	int n,x[100];
	int i;
	int sum;
	int ave=0;

	scanf("%d\n",&n);
	while(i<n){
		scanf("%d",&x[i]);
		sum=sum+x[i];
		i++;
	}
	ave=(double)sum/(double)n+0.5;
	i=0;
	sum=0;
	while(i<n){
		sum=sum+(pow((ave-x[i]),2.0));
		i++;
	}
	printf("%d",sum);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int x1,y1,x2,y2,x3,y3,x4,y4,x,y;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	x=x2-x1;	y=y2-y1;
	x3=x2-y;	y3=y2+x;
	x4=x3-x;	y4=y3-y;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

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

	ll maxn = 2e5;
	vector<bool> isprime(maxn+1);
	FOR(i, 2, maxn) {
		isprime[i] = true;
	}
	FOR(i, 2, maxn) {
		if (isprime[i]) {
			for (int j = 2*i; j <= maxn; j += i) {
				isprime[j] = false;
			}
		}
	}
	
	FOR(i, x, maxn) {
		if (isprime[i]) {
			pv(i);
			return(0);
		}
	}
	return(0);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;

long long gcd(long long a,long long b){
  if(b==0)return a;
  if(a<b)return gcd(b,a);
  return gcd(b,a%b);
}

long long lcm(long long a,long long b){
  return a*b/gcd(a,b);
}

long long euler_phi(long long n){
  LL ret=n;
  for(LL k=2;k*k<n+2;k++){
    if(n%k==0){
      ret-=ret/k;
      while(n%k==0)n/=k;
    }
  }
  if(n!=1)ret-=ret/n;
  return ret;
}

long long power(__int128 n, __int128 e, __int128 mod){
  __int128 ret = 1;
  __int128 b = n;
  while(e){
    if(e%2!=0)
      ret*=b;
    ret%=mod;
    b*=b;
    b%=mod;
    e/=2;
  }
  return (LL)ret;
}

LL solve(LL a,LL m){
  LL tor=euler_phi(m);
  if(m==2)return (a%2==0)?2:1;
  LL big=lcm(tor,m);
  LL sub=(tor==1)?1:solve(a,tor);
  return big+power(a,sub,big);
}

int main(){
  cin>>n;
  LL a,m;
  REP(i,n){
    cin>>a>>m;
    if(a==1||m==1){cout<<1<<endl;continue;}
    cout<<solve(a,m)<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	string s;
	cin>>s;
	int ans=0;
	f(i,4){
		if(s[i]=='2') ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  cin >> s;
  int res = 0;
  for (uint i = 0; i < s.size() - 1; ++i) {
    if (s.substr(i, 2) == "BW" || s.substr(i, 2) == "WB") ++res;
  }
  cout << res << endl;
}


Measured memory_bytes: 512
def main():
  A = input()
  N = len(A)
  ans = 0
  for i in range(26):
    c = ord('a')+i
    c = chr(c)
    m = A.count(c)
    ans += m*(m-1)//2
  print(N*(N-1)//2-ans+1)
if __name__=='__main__':
  main()

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

int main() {
  string S;
  cin >> S;
  for(int i=0;i<S.size();i++) {
    if(S[i] == '1') {
      S[i] = '9';
    }
    else {
      S[i] = '1';
    }
  }
  cout << S << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 2016;
const ll inf = 2e18;

int n;
ll a[M], x;
ll b[M];

void read() {
  cin >> n;
  cin >> x;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
}


void kill() {
  fill(b, b + n, inf);

  ll ans = inf;

  for (ll k = 0; k < n; ++k) {
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
      b[i] = min(b[i], a[(i + n - k) % n]);
      sum += b[i];
    }

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

  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 256
d,g = map(int,input().split())
"""
PC = []
for i in range(d):
    pc = list(map(int,input().split()))
    PC.append(pc)
"""
PC =[list(map(int,input().split())) for i in range(d)]

def solve(g,i):
    if i<=0:
        return float('inf')
    n = min(int(g/(100*i)),PC[i-1][0])
    score = 100 * i * n
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if g > score:
        n += solve(g-score,i-1)
    return min(n,solve(g,i-1))

print(solve(g,d))

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

int main()
{
  int N,T;
  int ans=2001001001;
  cin>>N>>T;
  for (int i=0;i<N;i++){
    int A,B;
    cin>>A>>B;
    if (B<=T)
      ans=min(ans,A);
  }
  if (ans==2001001001)
    cout<<"TLE"<<endl;
  else
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  rep(i, n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> v;
  for (auto el : mp) v.push_back(el.second);
  sort(v.begin(), v.end(), less<int>());
  int ans = 0;
  int num = mp.size() - k;
  rep(i, num) ans += v[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13624
object Main {
  def main(args:Array[String]):Unit = {
    for (line <- scala.io.Source.stdin.getLines() if line != "0 0") {
      val Array(h, w) = line.split(" ").map(_.toInt)
      for (i <- 1 to h) {
        println("#" * w)
      }
      println()
    }
  }
}

Measured memory_bytes: 45188
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

ll dp[101][100*1000 + 1];

int main() {
    int N;
    ll W;
    cin >> N >> W;
    ll w[N], v[N];
    rep(i,N) cin >> w[i] >> v[i];
    
    rep(i,N+1)rep(j,100*1000+1) dp[i][j] = 1000000001;
    dp[0][0] = 0;
    
    // dp[i+1][j] = i番目までの品物から価値の総和がjになるように選んだときの重さの最小値
    rep(i,N)rep(j,100*1000+1) {
        if (v[i] > j) {
            dp[i+1][j] = dp[i][j];
        } else {
            dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); 
        }
    }

    int ans = 0;
    rep(i,100*1000+1) {
        if (dp[N][i] <= W) {
            ans = max(ans, i);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 79104
import java.io.*;
import java.util.*;

public class Main{

	static ArrayList<Integer> []adj;
	static int []dp;
	static int dp(int u) {
		if(dp[u]!=-1)
			return dp[u];
		int ans=0;
		for(int v:adj[u])
			ans=Math.max(ans, 1+dp(v));
		return dp[u]=ans;
		
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt(),m=sc.nextInt();
		adj=new ArrayList[n];
		dp=new int [n];
		for(int i=0;i<n;i++) {
			dp[i]=-1;
			adj[i]=new ArrayList<>();
		}
		while(m-->0) {
			int u=sc.nextInt()-1,v=sc.nextInt()-1;
			adj[u].add(v);
		}
		int ans=0;
		for(int i=0;i<n;i++)
			ans=Math.max(ans, dp(i));
		out.println(ans);
		out.close();

	}
	
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 61596
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll A,B;
	cin>>A>>B;
	if(A>=13)cout<<B<<endl;
	else if(A>=6)cout<<B/2<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
from math import ceil


def train(i, t):
    if i == n - 1:
        return t
    c, s, f = d[i]
    tt = f * ceil(t / f) if t > s else s
    return train(i + 1, tt + c)


if __name__ == '__main__':
    n = int(input())
    d = [[int(i) for i in input().split()] for _ in range(n - 1)]
    print(*[train(i, 0) for i in range(n)], sep="\n")

Measured memory_bytes: 3572
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>

template<class T>
T input()
{
	T val;
	std::cin >> val;
	return val;
}

int main()
{
	long long n, sum = 0;

	std::cin >> n;
	std::vector<long long> b;
	for (int i = 0; i < n; ++i)
		b.push_back(input<long long>()), sum += b[i];

	std::sort(b.begin(), b.end());

	std::cout << b[0] << " " << b[n-1] << " " << sum << std::endl;

	return 0;
}

Measured memory_bytes: 1344
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  h=LI()
  h=[0]+h
  h+=[inf]*k

  dp=[inf]*114514
  dp[1]=0
  for i in range(1,n):
    for j in range(1,k+1):
      dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
  # print(dp[:10])
  return dp[n]

# main()
print(main())


Measured memory_bytes: 82644
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Console;

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

  void solve()
  {
    var n = int.Parse(ReadLine());
    var s = ReadLine();
    var t = ReadLine();

    var machCnt = 0;
    for(var i = 0; i < n; i++)
    {
      if(s.Substring(i) == t.Substring(0, n - i))
      {
        machCnt = n - i;
        break;
      }
    }

    var ans = n * 2 - machCnt;
    WriteLine(ans);
  }
}

Measured memory_bytes: 11092
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let mut tmp = line.split_whitespace();
    let a: u16 = tmp.next().unwrap().parse().unwrap();
    let b: u16 = tmp.next().unwrap().parse().unwrap();
    let c: u16 = tmp.next().unwrap().parse().unwrap();
    if (a*100 + b*10 + c) % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int a,b; cin>>a>>b;
	cout << (a+b)%24 << endl;
	return 0;
}


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

int main(void){
    int A[] = {1,3,5,7,8,10,12};
    int B[] = {4,6,9,11};
    int C[] = {2};

    int x, y;
    cin >> x >> y;
    int counta = 0;
    int countb = 0;
    for(int i = 0; i < sizeof(A)/sizeof(int); i++){
       if(A[i] == x || A[i] == y)
          counta++;
    }
    for(int i = 0; i < sizeof(B)/sizeof(int); i++){
       if(B[i] == x || B[i] == y)
            countb++;
    }

    if(counta == 2 || countb == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = "#";
		while (true) {
			// 1 ≤ H ≤ 300
			Integer h = sc.nextInt();
			// 1 ≤ W ≤ 300
			Integer w = sc.nextInt();

			// H, W がともに 0 のとき、入力の終わり
			if (h == 0 && w == 0) {
				return;
			}

			for (Integer i = 0; i < h; i++) {
				for (Integer j = 0; j < w; j++) {

					System.out.print(a);

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

		}

	}
}


Measured memory_bytes: 35568
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> cards = new ArrayList<Integer>();
		for(int i = 0;i < n ;i++) {
			cards.add(sc.nextInt());
		}
		Collections.sort(cards);
		Collections.reverse(cards);
		int ans = 0;
		for(int i = 0;i < n;i++) {
			if(i % 2 == 0) ans += cards.get(i);
			else ans -= cards.get(i);
		}
		System.out.println(ans);
        sc.close();
	}
}

Measured memory_bytes: 22228
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

h,w = MI()
s = [list(input()) for _ in range(h)]
dist = [[-1]*(w) for _ in range(h)]
#最短距離を求めよう
black_cnt = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            dist[i][j] = 0
            black_cnt += 1
dist[0][0] = 0
d = deque()
d.append([0,0])
dx = [1,-1,0,0]
dy = [0,0,1,-1]
while d:
    v = d.popleft()
    x = v[0]
    y = v[1]
    for i in range(4):
        nx = x+ dx[i]
        ny = y+ dy[i]
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if dist[nx][ny] == -1:
            dist[nx][ny] = dist[x][y] + 1
            d.append([nx,ny])
if dist[-1][-1] == -1:
    print(-1)
else:
    shortest = dist[-1][-1]
    print(h*w - black_cnt -(shortest+1))


Measured memory_bytes: 10100
N = int(input())
red = [list(map(int, input().split())) for i in range (N)]
blue = [list(map(int, input().split())) for i in range (N)]
blue.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1], reverse=True)
pairs = 0
flag = [True for i in range(N)]
for i in range(N):
    for j in range(N):
        if blue[i][0] > red[j][0] and blue[i][1] > red[j][1] and flag[j]:
            pairs += 1
            flag[j] = False
            break
print(pairs)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;



  return 0;
}

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

#define MAX_V 100001
#define INF 1000000000000000001
typedef long long ll;

struct edge { ll to, cost; };
typedef pair<ll, ll> P; // firstは最短距離、secondは頂点の番号
vector<edge> G1[MAX_V],G2[MAX_V];
ll d1[MAX_V], d2[MAX_V];

void dijkstra1(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d1, d1 + MAX_V, INF);
	d1[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d1[v] < p.first) continue;
		for (ll i = 0; i < G1[v].size(); i++) {
			edge e = G1[v][i];
			if (d1[e.to] > d1[v] + e.cost) {
				d1[e.to] = d1[v] + e.cost;
				que.push(P(d1[e.to], e.to));
			}
		}
	}
}

void dijkstra2(ll s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d2, d2 + MAX_V, INF);
	d2[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d2[v] < p.first) continue;
		for (ll i = 0; i < G2[v].size(); i++) {
			edge e = G2[v][i];
			if (d2[e.to] > d2[v] + e.cost) {
				d2[e.to] = d2[v] + e.cost;
				que.push(P(d2[e.to], e.to));
			}
		}
	}
}

void solve(long long n, long long m, long long s, long long t, vector<long long> u, vector<long long> v, vector<long long> a, vector<long long> b){
	for(int i = 0 ; i < m ; i++){
    edge e1 = {v[i],a[i]};
    G1[u[i]].push_back(e1);
    edge e2 = {u[i],a[i]};
    G1[v[i]].push_back(e2);
	}
	for(int i = 0 ; i < m ; i++){
    edge e1 = {v[i],b[i]};
    G2[u[i]].push_back(e1);
    edge e2 = {u[i],b[i]};
    G2[v[i]].push_back(e2);
	}
	dijkstra1(s);
	dijkstra2(t);

	priority_queue<P, vector<P>, greater<P> > que;
	for(int i = 1 ; i <= n ; i++){
		P p = make_pair(d1[i]+d2[i], i);
    que.push(p);
	}
	P p = que.top(); que.pop();
	// printf("%lld\n", p.first);
	for(int i = 0 ; i < n ; i++){
		while (p.second <= i) {
			p = que.top(); que.pop();
			// printf("%lld\n", p.first);
		}
		printf("%lld\n", 1000000000000000-p.first);
	}

}

int main(){
	long long s;
	long long t;
	long long m;
	long long n;
	scanf("%lld",&n);
	scanf("%lld",&m);
	vector<long long> v(m-1+1);
	vector<long long> u(m-1+1);
	vector<long long> b(m-1+1);
	vector<long long> a(m-1+1);
	scanf("%lld",&s);
	scanf("%lld",&t);
	for(int i = 0 ; i <= m-1 ; i++){
		scanf("%lld",&u[i]);
		scanf("%lld",&v[i]);
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
	}
	solve(n, m, s, t, u, v, a, b);
	return 0;
}


Measured memory_bytes: 26352
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int N;cin >> N;
    vector<int> A(N);
    vector<int> X(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    int sum=0;
    for(int x:A){
        sum += x;
    }
    int dif_sum=0;
    for(int i=1;i<N-1;i+=2){
        dif_sum+=A[i];
    }
    X[0]=sum-2*dif_sum;
    for(int i=1;i<N;i++){
        X[i]=2*A[i-1]-X[i-1];
    }
    
    for(int i=0;i<N;i++){
        cout << X[i] << " ";
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 2048