akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef pair<int,int> P;
const int INF = 1e9+7;

int main(){
    ll n,sum=0;;
    cin >> n;
    map<ll,ll> a;
    rep(i,n){
        ll t;
        cin >> t;
        sum += t;
        if(a.count(t)){
            ++a[t];
        }else{
            a[t] = 1;
        }
    }
    ll q;
    cin >> q;
    rep(i,q){
        ll b,c;
        cin >> b >> c;
        if(a.count(b)){
            if(a.count(c)){
                sum += c*a[b];
                sum -= b*a[b];
                a[c] += a[b];
                a.erase(b);
            }else{
                sum += c*a[b];
                sum -= b*a[b];
                a[c] = a[b];
                a.erase(b);
            }
        }
        cout << sum << endl;
    }
}

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

using namespace std;


int main()
{
    int n;
    long long k;cin>>n>>k;
    vector<int>a(n+1);
    vector<int>path;
    for(int i=1;i<=n;i++)cin>>a[i];
    vector<int>vis(n+1);
    int temp=1;
    int st;
    while(1)
    {
        temp=a[temp];
        vis[temp]++;
        if(vis[temp]>1)
            { st=temp;break;}
        path.push_back(temp);
    }
    int cyc=0,acyc=0;
    for(int i=0;i<path.size();i++)
    {
        if(path[i]==st)break;
        acyc++;
    }
    k=k-1;
    cyc=path.size()-acyc;
    if(k<acyc) 
        cout<<path[k]; 
    else
        cout<<path[(k - acyc)%cyc + acyc];
    
return 0;
}


Measured memory_bytes: 5884
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n, k;
string s,t;



int main()
{
	cin >> s;
	rep(i, (s.size() + 1) / 2)
		cout << s[2 * i];
	cout << endl;
}


Measured memory_bytes: 512
//PLUS ULTRA

#include<bits/stdc++.h>
using namespace std;
     
     
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define mp make_pair
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define nfor(i,st,n) for(int i = st; i >= n ; i--)

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

const int N = 1e5 + 10 , mod =  1000000007;



int main(){
    SPEED;

    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	int k; cin >> k;
	cout << arr[k-1] << endl;    

    
    return 0;
}
      
       


Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char *argv[])
{
  char a;
  char c[5] = {'a', 'i', 'u', 'e', 'o'};
  
  scanf("%c", &a);
  
  for(int i = 0; i < 5; i++){
    if(a == c[i]){
      printf("vowel\n");
      break;
    }
    else if(i == 4){
      printf("consonant\n");
    }
  }
  
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String c1 = sc.next();
        String c2 = sc.next();
        String c3 = sc.next();

        // 主処理
        String result = "" + c1.charAt(0) + c2.charAt(1) + c3.charAt(2);

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
K,N = map(int, input().split())
A = list(map(int,input().split()))
B = [0]*N

for i in range(N):
    if i != N-1:
        B[i] = A[i+1]-A[i]
    else:
        B[i] = A[0] + K - A[i]

print(sum(B)-max(B))

Measured memory_bytes: 26576
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXM=MAXN-1;

int n;
int ghead[MAXN],gnxt[2*MAXM],gto[2*MAXM];

ll dfs(int at,int par) {
	ll ret=0; int me=0;
	for(int x=ghead[at];x!=-1;x=gnxt[x]) {
		int to=gto[x]; if(to==par) continue;
		ll cur=dfs(to,at);
		while((cur&(1LL<<me))||(ret&(1LL<<me))||(1LL<<me)<(cur&ret)) ++me;
		ret|=cur;
	}
	ret&=~((1LL<<me)-1); ret|=(1LL<<me);
	//printf("%d = %lld\n",at,ret);
	return ret;
}

void run() {
	scanf("%d",&n); REP(i,n) ghead[i]=-1;
	REP(i,n-1) {
		int a,b; scanf("%d%d",&a,&b); --a,--b;
		gnxt[2*i+0]=ghead[a]; ghead[a]=2*i+0; gto[2*i+0]=b;
		gnxt[2*i+1]=ghead[b]; ghead[b]=2*i+1; gto[2*i+1]=a;
	}
	ll res=dfs(0,-1);
	int ret=0; while(res>>(ret+1)) ++ret; printf("%d\n",ret);

}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
using namespace std;

void solve(){
  int n,k,c;
  cin>>n>>k>>c;
  string s;
  cin>>s;
  vector<int>to(k+5),rto(k+5);
  int cnt=0;
  rep(i,n){
    if(s[i]=='o')to[cnt]=i,i+=c,++cnt;
    if(cnt>=k)break;
  }
  cnt=0;
  for(int i=n-1;i>=0;--i){
    if(s[i]=='o')rto[k-1-cnt]=i,i-=c,++cnt;
    if(cnt>=k)break;
  }
  rep(i,k){
    if(to[i]==rto[i])cout<<to[i]+1<<endl;
  }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int MOD = 1e9+7;

const int N = 1e4+10;
const int M = 101;

int dp[N][M][2];
int md[M][10];
    
string s;
int d;

signed main()
{
    fast;
    
    cin >> s >> d;
    
    int n = s.length();
    reverse(s.begin(),s.end());
    
    f(i,d) f(j,10)
        md[i][j] = ((i - j)%d + d)%d;
    
    dp[0][0][0] = dp[0][0][1] = 1;
    
    for(int i=1;i<=n;i++) f(j,d)
    {
        f(v,10)
        {
            dp[i][j][1] = (dp[i][j][1] + dp[i-1][md[j][v]][1])%MOD;
        }
        
        f(v,s[i-1]-'0')
        {
            dp[i][j][0] = (dp[i][j][0] + dp[i-1][md[j][v]][1])%MOD;
        }
        
        dp[i][j][0] = (dp[i][j][0] + dp[i-1][md[j][s[i-1]-'0']][0])%MOD;
    }
    
    cout << ( dp[n][0][0] - 1 + MOD)%MOD;
}

Measured memory_bytes: 16128
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a, b int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &a, &b)

	fmt.Println(calc(b-a-1) - a)
}

func calc(n int) int {
	return (1 + n) * n / 2
}


Measured memory_bytes: 640
S=input()
T=input()
ret = float("inf")
for i in range(len(S)-len(T)+1):
    
    sub = S[i:i+len(T)]
    ans = 0
    for k in range(len(sub)):
        if sub[k] != T[k]:
            ans += 1
    ret = min(ans, ret)
print(ret)

Measured memory_bytes: 67568
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using pi = pair<ll,ll>;
using st = set<ll>;
using kiwi = queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;
#define MOD 1000000007
const ll mx = 1e5+123;
#define REP(i,n) for (ll i=1;i<=n;++i)
ll ans[mx];
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(){
    fastio;
    ll n, sum=0; cin>>n;
    for(ll x=1;x<101;++x){
        for(ll y=1;y<101;++y){
            for(ll z=1;z<101;z++){
                sum=x*x+y*y+z*z+x*y+y*z+z*x;
                if(sum>n) continue;
                ans[sum]++;
            }

        }
    }
    for(ll i=1;i<=n;++i)
        cout<<ans[i]<<endl;
return 0;
}


Measured memory_bytes: 3628
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def ok(m):
        an=m
        for h in hh:
            d=h-b*m
            if d>0:
                an-=(d+a-b-1)//(a-b)
            if an<0:return False
        return True

    n,a,b=MI()
    hh=[int(input()) for _ in range(n)]
    mx=max(hh)
    l=mx//a-1
    r=mx//b+2
    while l+1<r:
        m=(l+r)//2
        if ok(m):r=m
        else:l=m
    print(r)

main()

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

int main()
{
    int d,e;
    while(cin>>d>>e,d){
        double res=1000000;
        for(int x=0;x<=d;x++){
            int y=d-x;
            res=min(res,abs(e-sqrt(x*x+y*y)));



        }

        cout<<res<<endl;


    }


}

Measured memory_bytes: 3240
#include <bits/stdc++.h> 
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define Rep(i,s,t) for(long long i=s;i<t;i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
ll n,m;
vector<ll> a;
bool check(ll x){
  ll k=0;
  rep(i,n){
    ll fir=lower_bound(all(a),x-a[i])-a.begin();
    k+=n-fir;}
  return k<m;
}
int main(){
  ll ans=0;
  cin>>n>>m;
  a.resize(n);
  vector<ll> s(n+1,0);
  rep(i,n){cin>>a[i];}
  sort(all(a));
  ll ng=0,ok=2*a[n-1]+2;
  while(abs(ok-ng)>1){
    ll c=(ok+ng)/2;
    if(check(c)){ok=c;}
    else{ng=c;}
  }
  for(ll i=1;i<n+1;i++){
    s[i]=s[i-1]+a[i-1];}
  rep(i,n){
    ll p=lower_bound(all(a),ok-a[i])-a.begin();
    ll q=n-p;
    ans+=(q*a[i])+s[n]-s[p];
    m-=q;}
  ans+=ng*m;
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
   int i,n;
   scanf("%d",&n);
   int scan[n];
   for(i=0;i<n;i++){
      scanf("%d",&scan[i]);
   }
   for(i=n-1;i>=0;i--){
      printf("%d",scan[i]);
      if(i==0) break;
      printf(" ");
   }
   printf("\n");
   return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

#define int long long

using namespace std;


int partition(int p,int q,int product,int a,int k,int n){
	int ans=0;
	if(n==0)return 0;
	if(p==0)return 0;
	if(n>1&&p==1&&product*q<=a&&q>=k) ans +=1;
	if(n==1&&p==1&&product*q<=a) return 1;
	if(product*k>a) return 0;
	int mi,ma,p1,q1;
	mi = max(k,(q+p-1)/p);
	ma = n*q/p;
	for(int i=mi;i<=ma;i++){
		p1 = i*p-q;
		q1 = q*i;
		int gcd = __gcd(p1,q1);
		p1 = p1/gcd;
		q1 = q1/gcd;
		ans += partition(p1,q1,product*i,a,i,n-1);
	}
	return ans;
}



signed main(){
	int p,q,a,n;
	while(1){
		cin >> p >> q >> a >> n;
		if(p==0&&q==0&&a==0&&n==0)break;
		int gcd = __gcd(p,q);
		p = p/gcd;
		q = q/gcd;	
		cout << partition(p,q,1,a,1,n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> v(n, 0);
    for(int i = 0; i < n - 1; ++i){
        int tmp;
        std::cin >> tmp;
        ++v[tmp - 1];
    }
    for(int i = 0; i < n; ++i) std::cout << v[i] << std::endl;

    return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
int main(void){
  int a, b, op;
  while(1){
      scanf("%d %s %d", &a, &op, &b);
     
      if ( op == '+' ){
          printf("%d\n", a + b);
      } else if ( op == '-' ){
          printf("%d\n", a - b);
      } else if ( op == '*' ){
          printf("%d\n", a * b);
      } else if ( op == '/' ){
          printf("%d\n", a / b);
      } else {
          break;
      }
  }
 
  return 0;
}


Measured memory_bytes: 2104
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	unsigned long long X, Y, genkai = 1;
	cin >> X >> Y;
	for (unsigned long long i = 1; ; i++)
	{
		if (X * 2 <= Y)
		{
			genkai++;
			X *= 2;
		}
		else break;
	}
	cout << genkai << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin >> s;
	int n = s.length();
	//cout << n << " ";
	int ok = 0;
	string tmp = s;
	reverse(s.begin(), s.end());
	if(s != tmp)
		ok = 1;
	string hyy = s.substr(0, (n - 1) / 2);
	string hhh = s.substr((n + 3) / 2 - 1, n);
	//cout << hyy <<" "<< hhh <<endl;
	string t1 = hyy;
	reverse(hyy.begin(), hyy.end());
	string t2 = hhh;
	reverse(hhh.begin(), hhh.end());
	if(hyy != t1)
		ok = 1;
	if(hhh != t2)
		ok = 1;
	if(ok)
		cout << "No" <<endl;
	else
		cout <<"Yes" <<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def main():
    N = int(input())
    value = N % 10
    if value in [2, 4, 5, 7, 9]:
        out = 'hon'
    elif value in [0, 1, 6, 8]:
        out = 'pon'
    elif value in [3]:
        out = 'bon'

    print(out)
main()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	string s,t; cin>>s>>t;
	int n = s.size();
	vector<vector<int>> a(n+1,vector<int>(26,-1));
	for(int i=n-1; i>=0; i--){
		a.at(i) = a.at(i+1);
		a.at(i).at(s.at(i)-'a') = i+1;
	}
	ll cnt{},now{};
	for(auto i:t){
		if(a.at(0).at(i-'a')==-1){
			cout << -1 << endl;
			return 0;
		}
		if(a.at(now).at(i-'a')==-1){
			cnt++; now=0;
		}
		now = a.at(now).at(i-'a');
	}
	cout << cnt*n+now << endl;
	
}

Measured memory_bytes: 13824
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long
using namespace std;
int main()
{
	int a, b, ans = 0;
	int m[1000], n[1000];
	cin >> a >> b;
	for (int i = 1; i <= 999; i++)
		m[i] = ((1 + i)*i) / 2;
	for (int i = 1; i <999; i++)
		n[i] = m[i + 1] - m[i];
	int tenp = b - a;
	for (int i = 1; i < 999; i++)
	{
		if (tenp == n[i])
		{
			ans = m[i] - a;
			break;
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int res = b;
	if(a + b < c) res += a + b + 1;
	else res += c;
	cout << res << endl;
}

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

#define ll long long
#define forn(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_backD. Distinct Characters Queries
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define el endl
#define fio     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define tst cin>>t; while(t--)

typedef pair<ll,ll>pll;
typedef unordered_map<ll,ll>mll;
typedef vector<ll>vl;
typedef set<ll>sl;
typedef priority_queue<ll>prl;

const ll mod=1000000007;
// 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 gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


int main()
{

    fio

    ll t,n,i,j,m,k,a,b,c=0;

    //tst
    {

    string s,t;
    cin>>s>>t;

    if(s+t[t.size()-1]==t)
		cout<<"Yes"<<el;
	else
		cout<<"No"<<el;








    }


    return 0;
}






Measured memory_bytes: 3548
#include <stdio.h>
#include <math.h>
 
int main(void)
{
  double r, c, s;
 
  while(scanf("%lf", &r) != EOF)
  {
     
    c = 2.0 * r * M_PI;
    s = r * r * M_PI;
   
    printf("%.6lf %.6lf\n", s, c);
  }
 
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    int a = 0, ans = 0;
    for (auto &&i : s) {
        if(i == 'R') a++;
        else a = 0;
        ans = max(ans, a);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=1e6;
int n,x;
int a[110];
int sum=0;
int ans;
int main()
{
    cin>>n>>x;
    for(int i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
    sort(a,a+n);
    ans+=n;
    ans+=(x-sum)/a[0];
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,k;

  
  int a[100][100],b[100],n,m;
  long ans=0;
  
  scanf("%d %d", &n,&m);
  
  for(i=0;i<n;++i){
    for(k=0;k<m;++k){
      scanf("%d", &a[i][k]);
    }
  }
  
  for(i=0;i<m;++i){
    scanf("%d", &b[i]);
  }
  
  for(i=0;i<n;++i){
    for(k=0;k<m;++k){
      ans += a[i][k] * b[k];
    }
    printf("%ld\n",ans);
    ans=0;
  }
  
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll inf=1e7;
int main(void){
    ll n;
    cin>>n;
    vector<string> s;
    rep(0,i,n){
        string ns;
        cin>>ns;
        s.push_back(ns);
    }
    sort(s.begin(),s.end());
    vector<pair<ll,string>>p(n);
    ll c=1,c0=0;
    string fs="";
    rep(0,i,n){
        //cout<<s[i]<<endl;
        if(fs==""){
            fs=s[i];
        }else{
            if(fs==s[i]){
                ++c;
            }else{
                p[c0].first=-c;
                p[c0].second=fs;
                ++c0;
                fs=s[i];
                c=1;
            }
        }
    }
    //cout<<endl;
    p[c0].first=-c;
    p[c0].second=fs;
    ++c0;
    rep(c0,i,n){
        p[i].first=inf;
        p[i].second="";
    }
    sort(p.begin(),p.end());
    ll pmax=p[0].first;
    rep(0,i,n){
        if(p[i].first==pmax)cout<<p[i].second<<endl;
    }
}



Measured memory_bytes: 17520
@$_=$_ for@p=0..<>;map{unshift@a,$#p*~-$#p/2-$%;/ /;@{$B=$p[$']}>@{$A=$p[$`]}or$A^=$B^=$A^=$B;$%+=@$B*map$p[$$B[@$B]=$_]=$B,@$A if$B-$A}reverse<>;print"@a"

Measured memory_bytes: 139904
from collections import deque

N = int(input())
v = [[] for i in range(N)]

for i in range(N-1):
    x, y, w = map(int, input().split())
    v[x-1].append((y-1, w))
    v[y-1].append((x-1, w))

ans = [0 for i in range(N)]
bfs_map = [1 for i in range(N)]
bfs_map[0] = 0

q = deque()
q.append(0)

while q:
    x = q.popleft()
    for y, w in v[x]:
        if bfs_map[y]:
            if w%2 :
                ans[y] = ans[x] ^ 1
            else:
                ans[y] = ans[x]
            bfs_map[y] = 0
            q.append(y)
    
for i in ans:
    print(i)

Measured memory_bytes: 39936
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string a,b;
  cin >> a >> b;
  if(a[0] == b[2] && a[2] == b[0] && a[1] == b[1]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];
	sort(all(a));
	sort(all(b));
	if (n % 2)
	{
		cout << b[n / 2] - a[n / 2] + 1 << endl;
	}
	else
	{
		int res = (b[n / 2] + b[n / 2 - 1]) / 2 - (a[n / 2] + a[n / 2 - 1] + 1) / 2 + 1;
		if ((a[n / 2] + a[n / 2 - 1]) % 2)++res; 
		if ((b[n / 2] + b[n / 2 - 1]) % 2)++res;
		res += ((b[n / 2] + b[n / 2 - 1]) / 2 - (a[n / 2] + a[n / 2 - 1] + 1) / 2);
		cout << res << endl;
	}
}

Measured memory_bytes: 4832
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=1e3+5;
const int maxs=2e4+5;

int n;
int w[maxn],s[maxn],v[maxn],p[maxn];
ll dp[maxn][maxs],mx[maxn][maxs];

inline bool cmp(const int &i,const int &j){return (w[i]+s[i]<w[j]+s[j]);}

int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d%d%d",w+i,s+i,v+i);
	FOR(i,0,n) p[i]=i;
	sort(p,p+n,cmp);
//	FOR(i,0,n) printf("%d ",p[i]);
//	puts("");
	dp[0][0]=0;dp[0][w[p[0]]]=v[p[0]];
	FOR(i,w[p[0]],maxs) mx[0][i]=v[p[0]];
	FOR(i,1,n){
		FOR(j,0,maxs){
//			if(j<5) printf("i=%d j=%d j-w[p[i]]=%d s[p[i]]=%d v[p[i]]=%d\n",i,j,j-w[p[i]],s[p[i]],v[p[i]]);
			dp[i][j]=dp[i-1][j];
			if(j>=w[p[i]]) dp[i][j]=max(dp[i][j],mx[i-1][min(s[p[i]],j-w[p[i]])]+v[p[i]]);
		}
		mx[i][0]=dp[i][0];
		FOR(j,1,maxs) mx[i][j]=max(mx[i][j-1],dp[i][j]);
	}
/*	FOR(i,0,n){
		FOR(j,0,5) printf("%lld ",dp[i][j]);
		puts("");
	}
	FOR(i,0,n){
		FOR(j,0,5) printf("%lld ",mx[i][j]);
		puts("");
	}
*/	printf("%lld\n",mx[n-1][maxs-1]);
	return 0;
}


Measured memory_bytes: 313600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

int main() {

	long long int n;
	cin >> n;

	set<long long int> st;
	map<long long int, long long int> mp;
	
	long long int a;

	for (long long int i = 0; i < n; i++) {
		cin >> a;
		mp[a]++;
		st.insert(a);
	}

	long long int ans = 0;

	for (set<long long int>::iterator ite = st.begin(); ite != st.end(); ite++) {
		if (mp[(*ite)] % 2 == 1) {
			ans++;
		}
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define LEN 100005

using namespace std;

typedef struct pp
{
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x)
{
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue()
{
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int main()
{
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for (i = 1; i <= n; i++)
  {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while (head != tail)
  {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0)
    {
      enqueue(u);
    }
    else
    {
      printf("%s %d\n", u.name, elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 12720
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
using namespace std;
const int SIZE=1005;
const int INF=1<<29;
const LL p=1e9+7;
bool sugar[4001],water[4001];
void solve(){
	int A,B,C,D,E,F;
	cin >>A >>B>>C>>D>>E>>F;
	sugar[0]=true;
	water[0]=true;
	REP(i,3001){
		sugar[i+C]|=sugar[i];
		sugar[i+D]|=sugar[i];
	}
	REP(i,3001){
		water[i+A]|=water[i];
		water[i+B]|=water[i];
	}
	long double maxim=0;
	int sizes=0,sugars=-1;
	REP(i,3001)
		REP(j,3001){
			long double g=i+j*100;
			if(sugar[i] && water[j]);
			else continue;
			if(i>j*E) continue;
			if(g>F) continue;
			if(sugars*(i+j*100)<=sizes*i){
				
				sizes=g;
				sugars=i;
			}			
		}
	cout << sizes <<" " << max(0,sugars) << endl;

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

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int main() {
    long n;
    cin >> n;
    long nn = n + 2;
    long l = 1;
    while (l <= abs(n)) {
        l *= 4;
        nn += 2 * l;
    }
    vector<int> rem;
    while (nn > 0) {
        rem.push_back(nn % 4);
        nn /= 4;
    }
    string ans = "0";
    for (int i = rem.size()-1; i >= 0; i--) {
        if (rem[i] == 0) ans += "10";
        else if (rem[i] == 1) ans += "11";
        else if (rem[i] == 2) ans += "00";
        else ans += "01";
    }
    size_t first = ans.find("1");
    if (first == string::npos) {
        cout << "0" << endl;
    } else {
        cout << ans.substr(first) << endl;
    }
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
money = []

for i in range(2 ** n):
    value = [0] * (m+1)
    for j in range(n):
        if (i >> j) & 1:
            value = [value[k]+books[j][k] for k in range(m+1)]
            
    for l in range(m):
        if value[l+1] < x:
            break
        elif l == m-1:
            money.append(value[0])
            
if len(money) == 0:
    print('-1')
else:
    print(min(money))

Measured memory_bytes: 9220
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R = sc.nextInt();
		int ans = 0;
		
		if(N<10){
			ans = R+100*(10-N);
        }else {
			ans = R;
        }
		System.out.println(ans);
    }
}


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

long long ans[2020][700], sum[2020][700], all;
int n, i, j, k;
const long long M=1000000007;
int main() {
	cin>>n;
	for(i=3;i<=n;i++) {
		ans[i][1]=1; 
		sum[i][1]=(sum[i-1][1]+ans[i][1])%M;
		for(j=2; j*3<=n; j++){
			ans[i][j]=sum[i-3][j-1];
			sum[i][j]=(sum[i-1][j]+ans[i][j])%M;
		}
	}
	for(all=0,i=1;i*3<=n;i++) all+=ans[n][i];
	all%=M;
	cout<<all<<endl;
	return 0;
}


Measured memory_bytes: 24884
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";  
  cout << "parent = " << T[u].p <<  ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL) cout << "root, ";
  else if (T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i) cout << ", ";
    cout << c;
  }
   cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL) rec(T[u].r, p);
  if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
  int i, j, d, v, c, l, r;
  cin >> n;
  for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for (i = 0; i < n; i++) {
    cin >> v >> d;
    for (j = 0; j < d; j++) {
      cin >> c;
      if (j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for (i = 0; i < n; i++) print(i);

  return 0;
}


Measured memory_bytes: 7768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,ans=0;
    cin >>n;
    vector<int>x(n);
    
    for(int i=0;i<n;i++){
        cin >> x[i];
        ans+=pow(x[i],2);
    }
    
    for(int i=1;i<=100;i++){
        long long res=0;
        for(int j=0;j<n;j++){
            res+=pow(x[j]-i,2);
        }
        
        ans=min(ans,res);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>
using namespace std;
long long inline read()
{
    long long x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
	long long N;
	N=read();
	for(long long h=1;h<=3500;++h)
		for(long long n=1;n<=3500;++n)
		{
			long long fm=N*h*n;
			long long fz=4*h*n-N*n-N*h;
			if(fz==0)
				continue;
			long long w=(fm/fz);
			if(fm%fz==0&&w>=1)
			{
				printf("%lld %lld %lld",h,n,w);
				return 0;
			}
		} 
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {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 gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}
const int N=1E5+1;
ll ret;
vi g[N];
int k;

void add_edge(int u,int v){g[u].push_back(v);g[v].push_back(u);}
void dfs(int node,int p){
    int i=2;
    for(int c:g[node]){
        if (c!=p){
            ret = (ret*(k-i++))%MOD;
            dfs(c,node);
        }
    }
}

int main() {
    READ(0);
    int n;cin>>n>>k;
    FOR(i,n-1) {
        int u, v;
        cin >> u >> v;
        add_edge(u - 1, v - 1);
    }
    ret = k;
    int i=1;
    for(int c:g[0]){
        ret = (ret*(k-i++))%MOD;
        dfs(c,0);
    }
    cout << ret;
    return 0;
}



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


int sum_of_digits(int n)
{
	int sum = 0;
	while(n > 0)
	{
		sum += n%10;
		n /= 10;
	}
	return sum;
}

int main()
{
	int n; cin >> n;
	int minval = 1e9;
	for(int i = 1; i < n; ++i)
	{
		int x = sum_of_digits(i) + sum_of_digits(n-i);
		minval = min(minval, x);
	}
	cout << minval << endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
		tree_order_statistics_node_update> indexed_multiset;



int n;

int main(){	
	cin>>n;
	vector<int>vi;
	int mxn = 0 , mn = 1e8 , plmn = -1 , plmxn = -1;
	for(int i = 0; i< n ; i++){
		int x ; cin>>x;
		vi.push_back(x);
		if(x < mn){
			mn = x;
			plmn = i;
		}if(x >mxn){
			mxn = x;
			plmxn = i;
		}
	}
	vector<pair<int,int>>ans;
	if(abs(mxn) > abs(mn)){
		//0 --- > n
	for(int i =0 ; i < n ; i++){
		ans.push_back({plmxn+1,i+1});
		vi[i]+=vi[plmxn];
	}
	//0---->n-1
	for(int i = 0; i < n - 1 ;i++){
		ans.push_back({i+1 , i+2});
		vi[i+1]+=vi[i];
	}
	}//mxn<mn i -- > n
	// n-1 -- > i
	else{
		for(int i = 0; i <n ; i++){
			ans.push_back({plmn+1,i+1});
			vi[i]+=vi[plmn];
		}
		for(int i = n-1 ; i>= 1 ; i--){
			ans.push_back({i+1,i});
			vi[i-1]+=vi[i];
		}
	}
	//for(int i =0 ;i < n ; i++)cout<<vi[i]<<" ";
	cout<<(int)ans.size()<<endl;
	for(int i = 0; i < (int)ans.size() ; i++)
	{
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 200010
#define inf (1LL<<60)
typedef long long ll;
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int x[N];
struct SegmentTree {
    ll Min1[N<<2],Min2[N<<2],tag[N<<2];
    #define lc k<<1
    #define rc k<<1|1
    #define mid ((l+r)>>1)
    inline void upd(int k) {
        Min1[k]=min(Min1[lc],Min1[rc]);
        Min2[k]=min(Min2[lc],Min2[rc]);
    }
    inline void down(int k) {
        if (!tag[k]) return;
        tag[lc]+=tag[k],Min1[lc]+=tag[k],Min2[lc]+=tag[k];
        tag[rc]+=tag[k],Min1[rc]+=tag[k],Min2[rc]+=tag[k];
        tag[k]=0;
    }
    inline void build(int k,int l,int r) {
        if (l==r) return Min1[k]=Min2[k]=inf,void();
        build(lc,l,mid),build(rc,mid+1,r),upd(k);
    }
    inline ll ask1(int k,int l,int r,int x,int y) {
        if (y<l || r<x) return inf;
        if (x<=l && r<=y) return Min1[k]; down(k);
        return min(ask1(lc,l,mid,x,y),ask1(rc,mid+1,r,x,y));
    }
    inline ll ask2(int k,int l,int r,int x,int y) {
        if (y<l || r<x) return inf;
        if (x<=l && r<=y) return Min2[k]; down(k);
        return min(ask2(lc,l,mid,x,y),ask2(rc,mid+1,r,x,y));
    }
    inline void Set(int k,int l,int r,int x,ll dat) {
        if (x<l || r<x) return;
        if (l==r) return 
            Min1[k]=min(Min1[k],dat-l),
            Min2[k]=min(Min2[k],dat+l),void();
        down(k),Set(lc,l,mid,x,dat),Set(rc,mid+1,r,x,dat),upd(k);
    }
    inline ll ask(int k,int l,int r) {
        if (l==r) return Min1[k]+l; down(k);
        return min(ask(lc,l,mid),ask(rc,mid+1,r));
    }
}T;
int main() {
    int n=read(),q=read();
    int a=read(),b=read();
    x[0]=a,T.build(1,1,n),T.Set(1,1,n,b,0);
    for (int i=1;i<=q;i++) {
        x[i]=read();
        ll tmp=min(T.ask1(1,1,n,1,x[i])+x[i],T.ask2(1,1,n,x[i],n)-x[i]);
        int dis=abs(x[i]-x[i-1]); T.tag[1]+=dis,T.Min1[1]+=dis,T.Min2[1]+=dis;
        T.Set(1,1,n,x[i-1],tmp);
    }
    cout<<T.ask(1,1,n)<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];



    int dp[n];
    memset(dp,0,sizeof(dp));

    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);

    for(int i=2;i<n;i++)
    {
        dp[i]=dp[i-2]+abs(arr[i]-arr[i-2]);
        dp[i]=min(dp[i],dp[i-1]+abs(arr[i]-arr[i-1]));
    }

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


}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    // vector<int> acount(n, 0);
    Int a[n];
    map<Int, Int> ac;
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        // acount[a[i]]++;
        if (!ac.insert({a[i], 1}).second) {
            ac[a[i]]++;
        }
    }

    Int ans[n] = {}, temp = 0;
    for (auto e : ac) {
        if (1 < e.second) {
            temp += (e.second * (e.second - 1) / 2);
        }
    }
    map<Int, Int> memo;

    for (Int i = 0; i < n; i++) {
        Int minians = 0;
        if (memo.count(a[i]) == 0) {
            if (1 < ac[a[i]]) {
                Int n = ac[a[i]];
                Int a = n * (n - 1) / 2, b = (n - 1) * (n - 2) / 2;
                minians = temp - a + b;
            } else {
                minians = temp;
            }

            memo.insert({a[i], minians});
        } else {
            minians = memo[a[i]];
        }

        ans[i] = minians;
    }

    for (Int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 22528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define _IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll N=3e5+5,mod=1e9+7,inf=1e18;
ll seg[4*N];

void update(ll rt,ll l,ll r,ll id,ll v)
{
    if(l>id||r<id)return;
    if(l==r)
    {
        seg[rt]=max(seg[rt],v);
        return;
    }
    ll md=(l+r)/2;
    update(rt*2,l,md,id,v);
    update(rt*2+1,md+1,r,id,v);
    seg[rt]=max(seg[rt*2],seg[rt*2+1]);
}

ll query(ll rt,ll l,ll r,ll i,ll j)
{
    if(l>j||r<i)return -inf;
    if(l>=i&&r<=j)return seg[rt];
    ll md=(l+r)/2;
    return max(query(rt*2,l,md,i,j),query(rt*2+1,md+1,r,i,j));
}

int main()
{
    _IO;
    ll n,k;cin>>n>>k;
    ll mx=0;
    while(n--)
    {
        ll x;cin>>x;
        ll p=query(1,0,N, max(0LL,x-k), min(N,x+k) );
        update(1,0,N,x,p+1);
        mx=max(mx,p+1);
    }
    cout<<mx<<"\n";

}


Measured memory_bytes: 11844
import java.util.*;
public class Main {
	public static void main(String[] args) {
	
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int Array_1[] = new int[N];
		int Array_2[] = new int[N];
		int count = 0;

			for(int k=0 ; k<N ; k++) {
				Array_1[k] = in.nextInt();
				Array_2[k] = Array_1[k];
			}
			Arrays.sort(Array_1);
			for(int k=0 ; k<N ; k++) {
				if(Array_1[k]!=Array_2[k]) {
					count++;
				}
			}
			if(count>2) {
				System.out.println("NO");
			}
			else {
				System.out.println("YES");
			}
	}

}


Measured memory_bytes: 35680
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n; cin >> n;
	vector<ll> a(n), b(n); map<ll, ll> m;
	rep(i, n) { cin >> a[i]; m[a[i]]++; }
	rep(i, n) { cin >> b[i]; m[b[i]]++; }

	rep(i, n + 2) {
		if (m[i] > n) { cout << "No\n"; return 0; }
	}

	reverse(all(b));
	rep(i, n) {
		if (a[i] == b[i]) {
			rep(j, n) {
				if (a[j] != a[i] && b[j] != b[i]) { swap(b[j], b[i]); break; }
				if (a[n - j - 1] != a[i] && b[n - j - 1] != b[i]) { swap(b[n - j - 1], b[i]); break; }
			}
		}
	}
	cout << "Yes" << endl;
	rep(i, n) {
		if (i == 0) { cout << b[i]; }
		else { cout << ' ' << b[i]; }
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 18772
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B =sc.nextInt();
        int C =sc.nextInt();
        int D =sc.nextInt();
        int ans=0;
        if (A< B){
            ans +=A;
            if (C<D){
                ans+=C;
            }else{
                ans +=D;
            }
        }else {
            ans += B;
            if (C < D) {
                ans += C;
            } else {
                ans += D;

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

Measured memory_bytes: 23764
def mxmi(a,b):
    if a<b:
        return a,b
    else:
        return b,a
from collections import deque
n = int(input())
tree = [[] for i in range(n)]
color = [0]*(n-1)
d = dict()
for i in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    d[(a-1,b-1)] = i
ans = 0
q = deque([(0,0,0)])
while q:
    cnt = 0
    f = 1
    now,prev,col = q.popleft()
    for node in tree[now]:
        cnt+=1
        if node !=prev:
            if f==col:f+=1
            q.append((node,now,f))
            a,b = mxmi(now,node)
            color[d[(a,b)]] = f
            f+=1
    ans = max(ans,cnt)


ls = list(d.items())
ls.sort(key=lambda x:x[1])
print(ans)
for i in range(n-1):
    print(color[i])


Measured memory_bytes: 54048
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
using namespace std;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


int main()
{

    ll X,N,tmp,A[102];
    cin >>X>>N;

    if(N==0){
        cout << X << endl;
        return 0;
    }

    rep(i,102){
        A[i]=0;
    }

    rep(i,N){
        cin >>tmp;
        A[tmp]=999;
    }

    rep(i,102){
        if(A[i]!=999) A[i]=abs(X-i);
    }

    ll tmp2=990,ans=101;

    for(ll i=101;i>=0;i--){
        if(A[i]<=tmp2){
            tmp2=A[i];
            ans=i;
        }
    }

    cout << ans << endl;

    return 0;


}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] == b[i] && a[i] == c[i]) continue;
		if(a[i] != b[i] && b[i] != c[i] && a[i] != c[i]){
			ans += 2;
			continue;
		}
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int happy = 0;

		happy += (x/500)*1000;
		happy += ((x%500)/5)*5;
		System.out.println(happy);
			
	    scan.close();	
    }
}

Measured memory_bytes: 21844