akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
const ll M=1e9+7;
const int MAXN=3e5+4;
const int MAXN2=5e4;



int main(){

	int n; sfi(n)

	vector<ll> v(401);

	ll sum[401];

	memset(sum,0,sizeof(sum));

	f(i,1,n+1)
	cin>>v[i];

	f(i,1,n+1){
		sum[i]=sum[i-1];
		sum[i]+=v[i];
	}

	ll dp[401][401];

	for(int l=1;l<=n;l++){
		dp[l][l]=0;
	}

	for(int i=1;i<n;i++){
		dp[i][i+1]=v[i]+v[i+1];
	}

	for(int l=3;l<=n;l++){
		for(int i=1;i+l-1<=n;i++){
			int j=i+l-1;

			dp[i][j]=LONG_LONG_MAX;
			for(int k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+(sum[j]-sum[i-1]));
			}
		}
	}


	cout<<dp[1][n];


	return 0;	
}

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

using namespace std;

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

    if(a==0){
        cout << "1" << endl;
    }
    else if(b==0){
        cout << "2" << endl;
    }
    else if(c==0){
        cout << "3" << endl;
    }
    else if(d==0){
        cout << "4" << endl;
    }
    else if(e==0){
        cout << "5" << endl;
    }

    return 0;
}

Measured memory_bytes: 3556
// inputに入力データ全体が入る
function Main(input) {
    var a = input[0].split(" ")[0]-0;
    var b = input[0].split(" ")[1]-0;
    var s = input[1];
    var rx = new RegExp("^\\d{" + a + "}-\\d{" + b + "}$");
    
    console.log(rx.test(s)?"Yes":"No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 7372
#include <stdio.h>

int main(void){
	int saikoro[6];
	int q,i;
	int top,front;
	int result;


	for(i=0; i<6; i++){
		scanf("%d",&saikoro[i]);
	}
	scanf("%d",&q);
	for(i=0; i<q; i++){
		scanf("%d %d",&top,&front);
		result = dice(saikoro,top,front);
		printf("%d\n",result);
	}

	
	return 0;
}
int dice(int saikoro[6], int top, int front){

		if(top == saikoro[0]){
			if( front == saikoro[1]) return saikoro[2];
			if( front == saikoro[2]) return saikoro[4];
			if( front == saikoro[3]) return saikoro[1];
			if( front == saikoro[4]) return saikoro[3];
		}
		if(top == saikoro[1]){
			if( front == saikoro[0]) return saikoro[3];
			if( front == saikoro[2]) return saikoro[0];
			if( front == saikoro[3]) return saikoro[5];
			if( front == saikoro[5]) return saikoro[2];
		}
		if(top == saikoro[2]){
			if( front == saikoro[0]) return saikoro[1];
			if( front == saikoro[1]) return saikoro[5];
			if( front == saikoro[4]) return saikoro[0];
			if( front == saikoro[5]) return saikoro[4];
		}
		if(top == saikoro[3]){
			if( front == saikoro[0]) return saikoro[4];
			if( front == saikoro[1]) return saikoro[0];
			if( front == saikoro[4]) return saikoro[5];
			if( front == saikoro[5]) return saikoro[1];
		}
		if(top == saikoro[4]){
			if( front == saikoro[0]) return saikoro[2];
			if( front == saikoro[2]) return saikoro[5];
			if( front == saikoro[3]) return saikoro[0];
			if( front == saikoro[5]) return saikoro[3];
		}
		if(top == saikoro[5]){
			if( front == saikoro[1]) return saikoro[3];
			if( front == saikoro[2]) return saikoro[1];
			if( front == saikoro[3]) return saikoro[4];
			if( front == saikoro[4]) return saikoro[2];
		}
		return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    string s; cin >> s;
    int n = s.size();
    int head = 0, tail = n-1;
    while(s[head]!='A') head++;
    while(s[tail]!='Z') tail--;

    cout << tail - head + 1;
}


Measured memory_bytes: 644
#include <stdio.h>

#define DATA_MAX     (52)
#define MAX(a,b)    ((a)>(b)?(a):(b))

int scan_line(int *buf){
    int cnt;
    char c;
    cnt = 0;
    while( scanf("%d%c",&buf[cnt],&c)>0 ){
        cnt++;
        if( c == '\n' )break;
    }
    return cnt;
}

int main(){
    int buf[2][DATA_MAX];
    int cnt[2];
    int now,pre;
    int i;

    cnt[0] = scan_line(buf[0]);
    pre = 0;
    now = 1;

    while( (cnt[now] = scan_line(buf[now])) > 0 ){
        if( cnt[pre] < cnt[now] ){
            /* upper half */
            /*     0       1     */
            /*   /   \   /   \   */
            /* 0       1       2 */
            /* +       +       + */
            /* 0    MAX(0,1)   1 */
            buf[now][0] += buf[pre][0];
            for( i=1; i<cnt[now]-1; i++){
                buf[now][i] += MAX(buf[pre][i-1], buf[pre][i]);
            }
            buf[now][i] += buf[pre][i-1];
        }else{
            /* lower half */
            /* 0       1       2 */
            /*   \   /   \   /   */
            /*     0       1     */
            /*     +       +     */
            /* MAX(0,1) MAX(1,2) */
            for( i=0; i<cnt[now]; i++){
                buf[now][i] += MAX(buf[pre][i], buf[pre][i+1]);
            }
        }
        pre = now;
        now = 1-pre;
    }

    printf("%d\n",buf[pre][0]);

    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		int cards[][] = new int[4][13];
		String m[] = {"S", "H", "C", "D"};
		
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();

		for(int z=1; true; z++){

			if (z > x) break;
			
			String i = scan.next();
			int j = scan.nextInt();
			int I = 0;
			int J = j-1;
			
			if(i.equals ("S")) I = 0;
			else if(i.equals ("H")) I = 1;
			else if(i.equals ("C")) I = 2;
			else if(i.equals ("D")) I = 3;
			cards[I][J] = j;
		}
		
		//?????????
		for (int I=0; true; I++){
			for(int J=0; true; J++){
				if((cards[I][J]) == 0){
					System.out.print(m[I] + " ");
					System.out.println(J+1);
				}
				if(J==12) break;
			}
			if (I==3) break;
		}
		
		
	}

}

Measured memory_bytes: 26232
using System;

namespace abc160_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            var happy = 0;
            happy += (int)(n/500) * 1000;
            happy += (int)(n%500/5) * 5;
            Console.WriteLine(happy);
       }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
//define
#define itn int //for int typo error
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto&a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second
//typedef
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
typedef pair<int, int> pii;
inline int rint(){int x; scanf("%d", &x); return x;}
//can modify here
const ll mod = 1000000007;
//don't ever modify here, a^b % mod function, extended euclid algo, gcd
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll eea(ll a, ll b, ll &x, ll &y){if(!b){x=1,y=0;return a;} ll x1,y1; ll d = eea(b,a%b,x1,y1);x=y1;y=x1-(ll)(a/b)*y1;return d;}
ll gcd(ll a, ll b){ll x; ll y; return eea(a,b,x,y);}


//code here
void solve()
{
    int n;
    cin >> n;
    long arr[n];
    rep(i,0,n)
        cin >> arr[i];
    sort(arr, arr+n);
    rep(i,0,n-1)
        if(arr[i] == arr[i+1])
        {
            cout << "NO";
            return;
        }
    cout << "YES";
}


int main() {
    //For faster IO, comment out for interative problems
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	solve();
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 998244353
#define pi 3.141592653589793
const int N = 2000001;
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n, x, y;
    cin >> n >> x >> y;
    ll ans[n];
    memset(ans, 0, sizeof ans);
    for (int i = 1; i < n + 1; i++) {
        for (int j = i + 1; j < n + 1; j++) {
            int h = min({j - i, abs(x - i) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j)});
            ++ans[h];
        }
    }

    for (int i = 1; i < n; i++) {
        cout << ans[i] << '\n';
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int k,x;
  cin>>k>>x;

  FOR(i,x-k+1,x+k){
    cout<<i<<' ';
  }
  cout<<endl;

}

Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::marker::*;
use proconio::*;
use rand::prelude::*;
use std::time::*;

#[derive(Debug)]
struct State {
    D: usize,
    c: Vec<i64>,
    s: Vec<Vec<i64>>,
    t: Vec<usize>,
    lasts: Vec<usize>,
    d: usize,
    score: i64,
}

impl State {
    fn new(D: usize, c: Vec<i64>, s: Vec<Vec<i64>>) -> State {
        State {
            D,
            c,
            s,
            t: vec![0; D],
            lasts: vec![0; 26],
            d: 0,
            score: 0,
        }
    }

    fn set_init(&mut self) {
        let mut rng = thread_rng();
        for i in 0..self.D {
            self.t[i] = rng.gen_range(0, 26);
        }
    }

    fn calc(&mut self) -> i64 {
        let mut score = self.s[self.d][self.t[self.d]];

        self.lasts[self.t[self.d]] = self.d + 1;
        for i in 0..26 {
            score -= (self.d + 1 - self.lasts[i]) as i64 * self.c[i];
        }

        self.d += 1;
        score
    }

    fn result(&self) -> i64 {
        let mut score = 0;
        let mut lasts = vec![0; 26];
        for d in 0..self.D {
            score += self.s[d][self.t[d]];
            let l = lasts[self.t[d]];
            lasts[self.t[d]] = d + 1;
            score -= self.c[self.t[d]] * ((d - l) * (d - l + 1) / 2) as i64;
        }

        for i in 0..26 {
            let l = lasts[i];
            score -= self.c[i] * ((self.D - l) * (self.D - l + 1) / 2) as i64;
        }

        score
    }
}

fn main() {
    input! {
        D: usize,
        c: [i64; 26],
        s: [[i64; 26]; D],
    };
    let mut obj = State::new(D, c, s);
    let mut rng = thread_rng();
    let time = SystemTime::now();
    let mut pre_score = -1000000;
    obj.set_init();

    loop {
        let d = rng.gen_range(0, D);
        let q = rng.gen_range(0, 26);
        let tq = obj.t[d];
        obj.t[d] = q;
        let score = obj.result();
        if score > pre_score {
            pre_score = score;
        } else {
            obj.t[d] = tq;
        }

        if time.elapsed().unwrap().as_millis() > 1900 {
            break;
        }
    }

    for &t in &obj.t {
        println!("{}", t + 1);
    }
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, n *a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,m;
        cin>>n>>m;
        ll a[n][m];
        REP(i,0,n)
        {
            REP(j,0,m)
            {
                char t;
                cin>>t;
                if(t=='.') a[i][j]=0;
                else a[i][j]=1;
            }
        }
        ll dp[n][m];
        dp[n-1][m-1]=1;
        REPI(i,0,n)
        {
            REPI(j,0,m)
            {
                if(i==n-1&&j==m-1) continue;
                dp[i][j]=0;
                if(a[i][j]==1) continue;
                if(i<n-1)
                {
                    dp[i][j]+=dp[i+1][j];
                    dp[i][j]%=M;
                }
                if(j<m-1)
                {
                    dp[i][j]+=dp[i][j+1];
                    dp[i][j]%=M;
                }
            }
        }
        cout<<dp[0][0];
    }
 
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a < b && b < c) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
n=int(input())
s=[]
s.append(input())
s.append(input())
mod=10**9+7
state=0
parallel=0
ans=1
for i in range(n):
    if s[0][i]==s[1][i]:
        if i==0:
            ans=3
        else:
            if state==0:
                ans*=2
        state=0
    else:
        if i<2:
            if i==1:
                ans=6
                state=1
        else:
            if parallel==0:
                parallel+=1
            else:
                parallel=0
                if state==0:
                    ans*=2
                else:
                    ans*=3
                state=1
    if ans>mod:
        ans%=mod
print(ans)


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int kN = 42;
int N;
int B[kN];
long long C[kN];
typedef pair<int,int> P;

void print(long long l, int n) {
  string s;
  rep(i,n) s += (l >> i & 1) ? '1' : '0';
  cout << s << endl;
}

int solve() {
  const int half = N / 2;
  int ret = 0;
  
  // 開いているビット, 最大値 のペアを作成
  map<int,int> hash;
  
  // 前半分を列挙
  for (int S = 1; S < (1 << half); ++S) {
    if (!(S & 1)) continue;
    // 整合性チェック と コストを求める
    bool ok = true;
    int cost = 0;
    long long t = 0;
    for (int i = 0; i < half && ok; ++i) {
      if (S >> i & 1) {
        if (!(t >> i & 1)) {
          t |= C[i];
          cost += B[i];
        }
        else {
          ok = false;
        }
      }
    }
    if (!ok) continue;
    // 残りの空いているビットを列挙
    int zeros = 0;
    for (int i = 0; i < N - half; ++i) {
      if (!(t >> (i + half) & 1))
        zeros |= (1<<i);
    }
    hash[zeros] = max(hash[zeros], cost);
    // コスト更新
    ret = max(ret, cost);
  }
  
  vector<P> vp;
  foreach(hash,it) {
    vp.push_back(P(it->second, it->first));
  }
  sort(vp.begin(), vp.end(), greater<P>());

  // 後ろ半分を列挙
  for (int S = 0; S < (1 << (N - half)); ++S) {
    // 整合性確認
    bool ok = true;
    long long t = 0;
    int cost = 0;
    for (int i = 0; i < (N - half) && ok; ++i) {
      if (S >> i & 1) {
        if (!(t >> (i + half) & 1)) {
          t |= C[i+half];
          cost += B[i+half];
        }
        else {
          ok = false;
        }
      }
    }
    if (!ok) continue;
    // コスト更新
    rep(i,vp.size()) {
      if ((vp[i].second | S) != vp[i].second) continue;
      ret = max(ret, vp[i].first + cost);
      break;
    }
  }
  return ret;
}

void input() {
  map<string,int> hash;
  string a, d;
  int b, c, cnt = 0;
  memset(C, 0, sizeof C);

  rep(i,N) {
    cin >> a >> b >> c;
    if (hash.count(a) == 0) {
      hash[a] = cnt++;
    }
    B[hash[a]] = b;
    rep(j,c) {
      cin >> d;
      if (hash.count(d) == 0) {
        hash[d] = cnt++;
      }
      C[hash[a]] += 1LL << hash[d];
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> N, N) {
    input();
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
  fast;

   ll n;
   cin>>n;

   ll l[n];

   for(ll i=0;i<n;i++)
    cin>>l[i];

    sort(l,l+n);
    ll ans=0;

    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            ll x=l[i]+l[j];

            ll in=upper_bound(l+j+1,l+n,x-1)-l-j-1;
            ans+=in;
           // cout<<i<<" "<<j<<" "<<in<<endl;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int N;
	std::string S;
	
	cin >> N >> S;
	int cnt = 0;
	int ans = 0;
	
	for(int i = 0;i<N-1;i++){
		if(S[i] == S[i+1]){
			cnt++;
		}
		
	}
	
	ans = N - cnt;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,k,s = map(int,input().split())
    if s == 10**9:
        a = [10**9]*k
        for i in range(n-k):
            a.append(1)
        print(*a,sep = " ")
        exit()
    elif s == 1:
        a = [1]*k
        for i in range(n-k):
            a.append(10**9)
        print(*a,sep = " ")
        exit()
    #elif n == 0:
        #print(*[],sep = " ")
    elif n == k:
        print(*[s for i in range(n)],sep = " ")
    else:
        a = [0]*n
        a[0] = 1
        for i in range(1,k+1):
            if i % 2 != 0:
                a[i] = s-1
            else:
                a[i] = 1
        for i in range(k+1,n):
            a[i] = 10**9
        print(*a,sep = " ")
    
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 9812
#include<iostream>
using namespace std;
const long long mode=1e9+7;
long long Mode(long long a,long long b){
	long long sum = 1;
	a=a%mode;
	while(b>0){
		if(b%2==1)		//判断是否是奇数，是奇数的话将多出来的数事先乘如sum
			sum=(sum*a)%mode;
		b/=2;
		a=(a*a)%mode;// 不断的两两合并再取模，减小a和b的规模
	}
	return sum;
}
int main(){
	int n,a[100010]={0},b[100010]={0},sum0=0;
	long long sum = 1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[a[i]]++;
	}
	for(int i=0;i<10010;i++){
		if(b[0]==2){
			cout<<0<<endl;
			return 0;
		}
		if(b[i]>2){
			cout<<0<<endl;
			return 0;
		}
	}
	if(n%2==0){
		cout<<Mode(2,n/2)%mode<<endl;
	}
	else cout<<Mode(2,(n-1)/2)%mode<<endl;
	return 0;
}


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

int enc(vector<int> a){
    int n = a.size();
    int ret = 0, th = 1;
    for(int i = 0; i < n; i++){
        ret += a[i] * th;
        th *= 3;
    }
    return ret;
}

vector<int> dec(int val, int n){
    vector<int> ret(n);
    for(int i = 0; i < n; i++){
        ret[i] = val%3;
        val /= 3;
    }
    return ret;
}

int pow(int a, int b){
    int ret = 1;
    while(b-- > 0)  ret *= a;
    return ret;
}

const int INF = 1<<30;

// 3^15 = 14348907 で十分間に合いそうだが、関数呼び出しが多いので危ないかもしれない
// どうやったら綺麗に書けるのかわからない

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        int ma = pow(3,n)-1;
        vector<int> dp(pow(3,n), INF);
        vector<int> a(n);
        for(int i = 0; i < 3; i++){
            int k;  cin >> k;
            while(k-- > 0){
                int x;  cin >> x;
                a[--x] = i;
            }
        }
        // state, step
        queue<int> q;
        q.push(enc(a));
        dp[enc(a)] = 0;
        int ans = m+1;
        while(!q.empty()){
            int p = q.front();  q.pop();
            if(dp[p] > m){
                break;
            }
            if(p == 0 || p == ma){
                ans = dp[p];
                break;
            }
            vector<int> v = dec(p, n);
            int big[3] = {-1,-1,-1};
            for(int i = 0; i < n; i++)  big[v[i]] = max(i, big[v[i]]);
            if(big[0] > big[1]){
                v[big[0]] = 1;
                int tmp = enc(v);
                if(dp[tmp] == INF){
                    dp[tmp] = dp[p]+1;
                    q.push(tmp);
                }
                v[big[0]] = 0;
            }
            if(big[1] > big[0]){
                v[big[1]] = 0;
                int tmp = enc(v);
                if(dp[tmp] == INF){
                    dp[tmp] = dp[p]+1;
                    q.push(tmp);
                }
                v[big[1]] = 1;
            }
            if(big[1] > big[2]){
                v[big[1]] = 2;
                int tmp = enc(v);
                if(dp[tmp] == INF){
                    dp[tmp] = dp[p]+1;
                    q.push(tmp);
                }
                v[big[1]] = 1;
            }
            if(big[2] > big[1]){
                v[big[2]] = 1;
                int tmp = enc(v);
                if(dp[tmp] == INF){
                    dp[tmp] = dp[p]+1;
                    q.push(tmp);
                }
                v[big[2]] = 2;
            }
        }
        cout << (ans > m ? -1 : ans) << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  string s;
  cin >> s;

  ll n = s.size();

  REP(i, s.size()) {
    if (s[i - 1] != s[i]) {
      s.erase(s.begin() + i - 1, s.begin() + i + 1);
      i -= 2;
      if (i < 0) {
        i = 0;
      }
    }
  }

  cout << n - s.size() << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>

int next_weeks_debt(int current) {
  current *= 1.05;
  int mod = current % 1000;
  if (mod != 0) { current += 1000 - mod; }
  return current;
}

int main() {
  int weeks;
  std::cin >> weeks;

  int current = 100000;
  for (int i = 0; i < weeks; ++i) {
    current = next_weeks_debt(current);
  }

  std::cout << current << std::endl;

  return 0;
}

Measured memory_bytes: 0
n = int(input())
W = [input() for _ in range(n)]
if (len(set(W)) != len(W)):
  print('No')
  exit()

for i in range(len(W) - 1):
  if (W[i][-1] != W[i+1][0]):
    print('No')
    exit()

print('Yes')


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    int ma = 0;
    rep(i,T){
        cin >> a[i];
        ma = max(ma, a[i]);
    }
    cout << max(0LL,ma*2-1-K) << endl;
    
    return 0;
}


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

int main(){
	int hp, a_size, temp;
	cin >> hp >> a_size;
	for(int i=0; i<a_size;i++){
		cin >> temp;
		hp -= temp;
		if(hp < 1) break;
	}
	if(hp < 1){
		cout << "Yes" << endl;
	} else {
		cout << "No"  << endl;
	}
	return 0;
}

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;


  vector<int> cnt(N, 1);
  vector<bool> flag(N, false);
  flag[0] = true;

  REP(i, M){
    int x, y;
    cin >> x >> y;
    x--; y--;
    if(flag[x]){
      flag[y] = true;
      if(cnt[x] == 1) flag[x] = false;
    }
    cnt[x]--; cnt[y]++;
  }

  int ans = 0;
  REP(i, N){
    if(flag[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {	
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int count;
		
		while(scan.hasNextInt()){
			count = 1;
			int addNum = scan.nextInt() + scan.nextInt();
			while(addNum>=10){
				count++;
				addNum/=10;
			}
			System.out.println(count);
		}
	}
}

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

int main(){
	string x;
	cin>>x;
	int sum = 0;
	for(int i=0;i<x.length();i++){
	    sum += ((int) x[i]) - 48;
	}
	if(sum%9==0){
	    cout<<"Yes";
	}
	else{
	    cout<<"No";
	}
}

Measured memory_bytes: 3724
package main

import "fmt"

func main() {
	var h, w, n int
	fmt.Scan(&h, &w, &n)
	a := (n + (w - 1)) / w
	b := (n + (h - 1)) / h
	fmt.Println(min(a, b))
}

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


Measured memory_bytes: 512
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var h = int.Parse(line[1]);
        var w = int.Parse(line[2]);
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            if (a >= h && b >= w) ans++;
        }
        Console.WriteLine(ans);
    }
}

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

int main (void) {
    char s[101];
    scanf("%s", s);
    int s_len=strlen(s), i, ans=0;
    for ( i=0; i<s_len/2; i++ ) {
        if ( s[i] != s[s_len-i-1] )
            ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
/*    Mohammed Sami Khan
                       মোহাম্মদ সামী খান
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

int main()
{
    fastio;
    ll t, n, m, x=0, y=0, p, q, r, i, j, d, f=0;
    string s, a="", b="";
    cin>>s;
    for(i=0;i<s.size();i++){
        if(i%2){
            a.push_back('1');
            b.push_back('0');
        }
        else {
            a.push_back('0');
            b.push_back('1');
        }
    }
    for(i=0;i<s.size();i++){
        if(s[i]!=a[i]) x++;
        if(s[i]!=b[i]) y++;
    }
    cout<<min(x, y);
}


Measured memory_bytes: 3932
class UnionFind:
    def __init__(self, size):
        self.parent = [-1]*size #非負なら親ノード，負ならグループの要素数

    def root(self, x): #root(x): xの根ノードを返す．
        if self.parent[x] < 0:
            return x
        elif self.parent[self.parent[x]] < 0:
            return self.parent[x]
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return -self.parent[self.root(x)]
        
        
n,m = [int(i) for i in input().split()]

T=UnionFind(n)
c=0
for _ in [0]*m:
    x,y,z=[int(i) for i in input().split()]
    if T.merge(x-1,y-1):
        c+=1

print(n-c)



Measured memory_bytes: 6232
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int A, B, AB, X, Y;
    cin >> A >> B >> AB >> X >> Y;
    ll ans = LL_INF;
    for(int Z = 0; Z <= 200000; Z+=2){
        ll money = Z * AB + max(X - Z / 2, 0) * A + max(Y - Z / 2, 0) * B;
        ans = min(ans, money);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#define sc(x) scanf("%d", (x))
#define pr(x) printf("%d\n", (x))

const int N = 2e5 + 10;

int a[N], e[N], o[N], n;

int main() {
	scanf("%d", &n);
	int mx = 0;
	for (int i = 1, x, y; i <= n; i += 2) {
		sc(&x); sc(&y);
		o[x]++; e[y]++;
		mx = std::max(mx, std::max(x, y));
	}
	int o1 = 0, o2 = 0, e1 = 0, e2 = 0;
	for (int i = 1; i <= mx; ++i) {
		if (o[i] > o[o1]) {
			o2 = o1;
			o1 = i;
		} else if (o[i] > o[o2]) {
			o2 = i;
		}
		if (e[i] > e[e1]) {
			e2 = e1;
			e1 = i;
		} else if (e[i] > e[e2]) {
			e2 = i;
		}
	}
	if (o1 != e1) printf("%d\n", n - o[o1] - e[e1]);
	else printf("%d\n", std::min(n - o[o1] - e[e2], n - o[o2] - e[e1]));
	return 0; 
}

Measured memory_bytes: 896
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a;
    cin>>a;
    int num=a/100;
    if(a>num*100+num*10+num){
        cout<<(num+1)*100+(num+1)*10+num+1<<endl;
    }
    else{
        cout<<num*100+num*10+num<<endl;
    }
}



Measured memory_bytes: 256
#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{
        cout << "a == b" << endl;
    }

    return 0;
}


Measured memory_bytes: 3060
#include<stdio.h>
long long ans;
void dfs(long long l, long long s) {
    if(l % s == 0) {
        ans += l * 2 - s;
        return;
    }
    ans += l / s * s * 2;
    dfs(s, l % s);
}
int main() {
    long long n, x;
    scanf("%lld%lld", &n, &x);
    ans = n;
    if(x > n - x) dfs(x, n - x);
    else dfs(n - x, x);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1692
#include<stdio.h>
#include<math.h>
int main(){
int n,d;
  scanf("%d %d",&n,&d);
  int count=0;
  for(int i=0;i<n;i++){
    long long int x,y;
    long double z;
  scanf("%lld %lld",&x,&y);
  z=x*x+y*y;
    z=sqrt(z);
    if(z<=d)
      count++;
  }
  printf("%d",count);
}


Measured memory_bytes: 2128
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }

int countDigit(int n)
{
  int digit = 1;
  while((n /= 10) != 0)
    digit++;
  return digit;
}

int main()
{
  int a = -2; //何進数かをここで設定できる
  int n; cin >> n;
  string ans;
  
  while(true){
    if(n%a==0){
      ans.insert(0,"0");
      if(n==0)break;
      n /=a;
      continue;
    }else{
      ans.insert(0,"1");
      if(n==1)break;
      n = (n-1)/a;
    }
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
    int x,y;
    node(int x,int y):x(x),y(y){};
    bool operator <(const node a)const {
        if(a.x==x)return a.y>y;
        return a.x<x;
    }
};
vector<node>red,blue,black;
map<node,int>mp;
bool cmp(node a,node b){
    return a.y<b.y;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        int x,y;
        cin>>x>>y;
        red.emplace_back(node(x,y));
    }
    for(int i=1;i<=n;++i){
        int x,y;
        cin>>x>>y;
        blue.emplace_back(node(x,y));
    }
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    int ans=0;
    for(auto i:red){
        int x=i.x;
        int y=i.y;
        for(auto j:blue){
            if(j.x>x&&j.y>y&&mp[j]==0){
                black.emplace_back(j);
                mp[j]=1;
            }
        }
        sort(black.begin(),black.end(),cmp);
        for(auto j:black){
            if(j.y>y&&mp[j]==1){
                mp[j]=2;
                ans++;
//                cout<<x<<" "<<y<<" "<<j.x<<" "<<j.y<<" "<<mp[j]<<endl;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005*2;
int n;
pii p[N];
LL cal1(){
	LL ans=0;
	For(i,1,n)
		ans+=p[i].fi;
	return ans;
}
LL cal2(){
	LL ans=0;
	For(i,1,n)
		ans+=p[i].se;
	return ans;
}
int v[N],id[N];
int vis[N];
bool cmpV(int a,int b){
	return v[a]<v[b];
}
bool Check(){
	For(i,1,n)
		if (vis[i*2-1]==vis[i*2])
			return 1;
	return 0;
}
int t0[N],t1[N];
LL now=0;
LL Solve1(){
	int mi=1;
	For(i,1,n)
		if (t0[i]<t0[mi])
			mi=i;
	int ma=mi==1?2:1;
	For(i,1,n)
		if (i!=mi)
			if (t1[i]>t1[ma])
				ma=i;
	return now+t0[mi]-t1[ma];
}
LL Solve2(){
	int ma=1;
	For(i,1,n)
		if (t1[i]>t1[ma])
			ma=i;
	int mi=ma==1?2:1;
	For(i,1,n)
		if (i!=ma)
			if (t0[i]<t0[mi])
				mi=i;
	return now+t0[mi]-t1[ma];
}
int main(){
	n=read();
	For(i,1,n)
		p[i].fi=read(),p[i].se=read();
	LL ans=min(cal1(),cal2());
	For(i,1,n)
		v[i*2-1]=p[i].fi,v[i*2]=p[i].se;
	For(i,1,n*2)
		id[i]=i;
	sort(id+1,id+n*2+1,cmpV);
	For(i,1,n)
		now+=v[id[i]],vis[id[i]]=1;
	if (Check())
		ans=min(ans,now);
	else {
		For(i,1,n)
			if (!vis[i*2-1])
				t0[i]=p[i].fi,t1[i]=p[i].se;
			else
				t0[i]=p[i].se,t1[i]=p[i].fi;
		ans=min(ans,Solve1());
		ans=min(ans,Solve2());
	}
	cout<<ans<<endl;
	return 0;
}
/*
6
+19 92
+64 64
78 +48
+57 +33
73 +6
95 73
*/

Measured memory_bytes: 4224
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
//#define ll long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};
#define double long double

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    double m;
    cin >> n >> m;
    int ans = n * m;
    cout << ans;
}


Measured memory_bytes: 3744
H,W = map(int,input().split())
L = []
for i in range(H):
    L.append((input()))
for i in range(H):
    for j in range(W):
        if L[i][j] == "#":
            flag = False
            if i-1 >=0 and L[i-1][j] == "#":
                flag = True
            if i+1 <H and L[i+1][j] == "#":
                flag = True
            if j-1 >=0 and L[i][j-1] == "#":
                flag = True
            if j+1 <W and L[i][j+1] == "#":
                flag = True
            if flag == False:
                print("No")
                exit()
print("Yes") 

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
long long n,m,i,j;
map<long long,char> mp;
string s,t;
void chg(long long x,char y)
{
	if (mp.count(x)&&mp[x]!=y)
	{
		cout<<"-1\n";
		exit(0);
	}mp[x]=y;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>s>>t;
	long long lcm=n/__gcd(n,m)*m;
	fz0k(i,n) chg(i*(lcm/n),s[i]);
	fz0k(i,m) chg(i*(lcm/m),t[i]);
	cout<<lcm<<endl;
	return 0;
}

Measured memory_bytes: 10880
import sys
input = sys.stdin.readline


def RecSum(S, i):
    if i > len(S) - 1:
        return eval(''.join(S))
    SS = S.copy()
    SS.insert(i, "+")
    return RecSum(S, i+1) + RecSum(SS, i+2)


S = list(input().rstrip('\n'))
print(RecSum(S, 1))


Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int k;
    string s;
    cin >> k >> s;
    if(s.size()<=k) cout << s << endl;
    else{
    for(int i=0;i<k;i++){
        cout << s[i];
    }
    cout << "..." << endl;
    }
}


Measured memory_bytes: 3628
from collections import deque, defaultdict

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

d = defaultdict(int)
d[A[0]] += 1
x = deque([A[0]])
ans = 0
for a in A[1:]:
    ans += x[0]
    d[x[0]] -= 1
    if d[x[0]] == 0:
        x.popleft()
    if d[a] == 0:
        x.append(a)
    d[a] += 2
print(ans)

Measured memory_bytes: 36728