akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define INF 1000000000
int cost[101][101];
int d[101];
int flag[101];
int n;
void dijkstra(int s){
    int i,j;
    d[s] = 0;
    
    
    while(1){
        int v = -1;
        for(i=0;i<n;i++){
            if(flag[i]==0 && (v==-1 || d[i] < d[v])){
                v = i;
            }
        }
        if(v == -1) break;
        flag[v] = 1;
        for(i=0;i<n;i++){
            int tmp = d[v]+cost[v][i];
            d[i] = d[i] < tmp ? d[i] : tmp;
        }
    }
}
int main(){
    int i,j;
    int u,k,v,c;
    scanf("%d",&n);
    
    for(i=0;i<n;i++) d[i] = INF;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++) cost[i][j] = INF;
    
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d%d",&v,&c);
            cost[u][v] = c;
            }
    }
    dijkstra(0);
    
    for(i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}



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


int main() {
    long long a(0),b(0),c(0),d(0);

    cin >> a >> b >> c >> d;

    long long ac = a * c;
    long long ad = a * d;
    long long bc = b * c;
    long long bd = b * d;

    long long res = std::max({ac, ad, bc, bd});
    cout << res;

}


Measured memory_bytes: 3224
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <tuple>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse(a.begin(), a.end());
#define fi first
#define se second
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define ans(a) cout << a << '\n';
#define res(a, n) a.resize(n);
#define read(a, n) a.resize(n); fori(n) cin >> a[i];
//#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef set<ii> sii;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 998244353;

void solve()
{
    int x;
    cin >> x;
    if (x >= 30) yes
    else no
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
   int n, m;
   cin >> n >> m;
   vector<vector<char>> a(n, vector<char>(n)), b(m, vector<char>(m));
   for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
          cin >> a[i][j];
      }
   }
   for(int i = 0; i < m; i++) {
      for(int j = 0; j < m; j++) {
          cin >> b[i][j];
      }
   }

   bool flag = 0;
   for(int i = 0; i < n - m + 1; i++) {
      for(int j = 0; j < n - m + 1; j++) {
          flag = 1;
          for(int k = i; k < m + i; k++) {
              for(int l = j; l < m + j; l++) {
                  if(a[k][l] != b[k - i][l - j]) {
                      flag = 0;
                  }
              }
          }
          if(flag) {
              cout << "Yes" << endl;
              return 0;
          }
      }
   }
   cout << "No" << endl;

   return 0;
}


Measured memory_bytes: 256
L, R = map(int, input().split())
U = [0]*2019
for i in range(L, min(L+2019, R)+1):
    U[i % 2019] = 1
ans = 10**18
for i in range(2019):
    if not U[i]:
        continue
    for j in range(i+1, 2019):
        if not U[j]:
            continue
        ans = min(ans, (i*j) % 2019)
print(ans)


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

void print(const int a[], const int n, const int count){
    for(int i = 0; i < n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
    cout << count << endl;
}

void selectionSort(int a[], int n){
    int count = 0;
    
    for(int i = 0; i < n; i++){
        int minj = i;
        int flag = 0;
        for(int j = i; j < n; j++){
            if(a[j] < a[minj]){
                minj = j;
                flag = 1;
            }
        }

        int tmp;
        tmp = a[i];
        a[i] = a[minj];
        a[minj] = tmp;
        if(flag == 1){
            count++;
        }
        //count++;
    }
    print(a, n, count);
}

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

    selectionSort(a, n);
    return 0;

}


Measured memory_bytes: 3124
#include <list>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

const int day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
	string s;
	cin >> s;

	int size = s.size();
	REP(i, size) {
		cout << s[size-i-1];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1168
#!/usr/bin/env python3


numbers = input().split(" ")
n = int(numbers[0])
m = int(numbers[1])
k = int(numbers[2])



numbers = input().split(" ")
a = [int(x) for x in numbers]
numbers = input().split(" ")
b = [int(x) for x in numbers]

#結果
#aを(i + 1)冊目まで(i冊)読んだときの冊数
r = [0] * (n + 1)

time_a = 0
time_b = 0
books_a = 0
books_b = 0

i = 0
while books_a < n:
    time_a += a[books_a]
    books_a += 1

    if time_a > k:
        books_a -= 1
        time_a -= a[books_a]
        break



while books_a >= 0:
    # if books_a == 0:
    #     print(time_a)
    while books_b < m:
        time_b += b[books_b]
        books_b += 1
        if time_b + time_a > k:
            books_b -= 1
            time_b -= b[books_b]
            break

    r[books_a] = books_a + books_b

    books_a -= 1
    time_a -= a[books_a]


print(max(r))



Measured memory_bytes: 50260
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var ret = 0L;
        for (int i = 1; i <= n; i++) ret += getAns(n, i, k);
        Console.WriteLine(ret);
    }
    public static int getAns(int n, int b, int k)
    {
        var c = n / b;
        var d = n % b;
        var w = Math.Max(0, b - k);
        if (k == 0) return b * c + d;
        else return w * c + Math.Max(0, d - k + 1);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>

int main() {
    using namespace std;
    
    string str;
    cin >> str;

    int part_size = str.size() / 2;
    int count = 0;
    for(int i = 0; i < part_size; ++i)
    {
        if(str[i] != str[str.size() - 1 - i])
        {
            ++count;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 760
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
    char s[21];
    cin >> s;
    int l=strlen(s);
    char b[l];
    int a=0;
    for(int i=l-1;i>=0;i--){
        b[a]=s[i];
        a++;
    }
    b[a]='\0';
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 1136
#include <iostream>

int main(int argc, char *argv[])
{
    int n, d;
    int ans;

    std::cin >> n >> d;

    // 一人で 2 * D + 1本みれる

    ans = (n + 2 * d) / (2 * d + 1);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int m, c;
vector<list<int> > desk;

int takeBook(int x)
{
    for(int i=0; ; ++i){
        for(list<int>::iterator it=desk[i].begin(); it!=desk[i].end(); ++it){
            if(*it == x){
                desk[i].erase(it);
                return i + 1;
            }
        }
    }
}

int putBook(int x, int first)
{
    for(int i=first; i<m; ++i){
        if(desk[i].size() < c){
            desk[i].push_back(x);
            return i + 1;
        }
    }
    desk[m].push_back(x);
    return m + 1;
}

int main()
{
    for(;;){
        int n;
        cin >> m >> c >> n;
        if(m == 0 && c == 0 && n == 0)
            return 0;

        vector<vector<int> > b0(n);
        for(int i=0; i<n; ++i){
            int k;
            cin >> k;
            b0[i].resize(k);
            for(int j=0; j<k; ++j)
                cin >> b0[i][j];
        }

        vector<int> b;
        for(int i=0; i<50; ++i){
            for(int j=0; j<n; ++j){
                if(i < b0[j].size())
                b.push_back(b0[j][i]);
            }
        }
        n = b.size();

        desk = vector<list<int> > (m+1);
        for(int i=0; i<100; ++i)
            desk[m].push_back(i);

        int ret = 0;
        for(int i=0; i<n; ++i){
            ret += takeBook(b[i]);
            if(desk[0].size() < c){
                ret += putBook(b[i], 0);
            }else{
                ret += putBook(b[i], 1);
                int x = desk[0].front();
                desk[0].pop_front();
                ++ ret;
                ret += putBook(x, 1);
                ret += takeBook(b[i]);
                ret += putBook(b[i], 0);
            }
        }

        cout << ret << endl;
    }
}

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

int main()
{
	int n, m, sum, ave;
	while (scanf("%d%d",&n,&m)==2&&n)
	{
		sum = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &ave);
			if (ave < m - ave) sum += 2 * ave;
			else
			{
				sum += 2 * (m - ave);
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

typedef long long LL;

int n;
LL a[100005];
unordered_map<int, bool> vis;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i += 1) {
    scanf("%lld", &a[i]);
  }
  LL ans = 0;
  ans += a[0] - 1;
  vis[1] = true;
  int odd = 3, even = 2;
  for (int i = 1; i < n; i += 1) {
    if (vis[a[i]]) {
      continue;
    }
    if (odd < even && a[i] == odd) {
      vis[a[i]] = 1;
      odd += 2;
      continue;
    }
    if (even < odd && a[i] == even) {
      vis[a[i]] = 1;
      even += 2;
      continue;
    }
    int x = min(odd, even);
    ans += (a[i] - 1) / x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5156
#include<iostream>
#include<vector>

using namespace std;

int main()
{
    int N,M;
    cin>>N>>M;
    vector<int>s(M),c(M),ans(3,-1);
    for(int i=0;i<M;i++){
        cin>>s[i]>>c[i];
    }
    for(int i=0;i<M;i++){
        if(ans[s[i]-1]!=-1&&ans[s[i]-1]!=c[i]){
            cout<<-1<<endl;
            exit(0);
        }
        ans[s[i]-1]=c[i];
    }
    for(int i=1;i<N;i++){
        if(ans[0]==-1){
            ans[0]=1;
        }
        if(ans[i]==-1){
            ans[i]=0;
        }
    }
    if(ans[0]==0&&N!=1){
        cout<<-1<<endl;
        exit(0);
    }
    if(M==0&&N==1){
        cout<<0<<endl;
        exit(0);
    }
    if(M==0&&N==2){
        cout<<10<<endl;
        exit(0);
    }
    if(M==0&&N==3){
        cout<<100<<endl;
        exit(0);
    }

    
    
    for(int i=0;i<N;i++){
        cout<<ans[i];
    }
    
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> A(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &A[i]);

    size_t q;
    scanf("%zu", &q);

    vector<int> m(q);
    int max_=0;
    for (size_t i=0; i<q; ++i) {
        scanf("%d", &m[i]);
        if (max_ < m[i])
            max_ = m[i];
    }

    vector<int> dp(max_+1, -1); dp[0]=0;
    for (size_t i=0; i<n; ++i)
        for (int j=0; j<=max_; ++j) {
            if (dp[j] >= 0) {
                dp[j] = 1;
            } else if (j<A[i] || dp[j-A[i]]<=0) {
                dp[j] = -1;
            } else {
                dp[j] = dp[j-A[i]]-1;
            }
        }

    for (size_t i=0; i<q; ++i)
        printf("%s\n", dp[m[i]]>=0? "yes":"no");

    return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a(100001);

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		a[l-1]++;
		a[r]--;
	}
	for(int i=1;i<=100000;i++) a[i]+=a[i-1];
	int res=0;
	for(int i=0;i<100000;i++) if(a[i]) res++;
	cout<<res<<endl;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> city(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    rep(k,n){
      if(a==k+1||b==k+1) city.at(k)++;      
    }
  }
  rep(i,n){
    cout << city.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
string s;
signed main(){
    cin>>s;
    int l=s.size();
    if(l==1){
        cout<<0<<endl;
        return 0;
    }
    string a=s.substr(0,l/2);
    string b="";
    for(int i=l;2*i>=l;i--){
        b=b+s[i];
    }
    int ans=0;
    rep(i,l/2){
        if(a[i]!=b[i+1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 3000
int vis[N],cnt[3],e[N][N],dp[N],f[N],n,i,j,m,o,p,col[N];
vector<pair<int,int> >ans;
void dfs(int x,int a)
{
	vis[x]=1,col[x]=a;cnt[a]++;
	for (int y=1;y<=n;y++) if (e[x][y])
	{
		if (vis[y]==1&&col[y]==col[x]) {printf("-1\n");exit(0);}
		if (vis[y]==0) dfs(y,a^1);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (i!=j) e[i][j]=1;
	for (i=1;i<=m;i++)
	{	
		scanf("%d %d",&o,&p);
		e[o][p]=e[p][o]=0;
	}
	for (i=1;i<=n;i++) if (vis[i]==0) 
	{
		cnt[0]=cnt[1]=0;
		dfs(i,0);
		ans.pb(mp(cnt[0],cnt[1]));
	}
	dp[0]=1;
	for (auto t:ans)
	{
		for (i=0;i<=n;i++) f[i]=0;
		for (i=0;i<=n;i++) if (dp[i]) f[i+t.fi]=f[i+t.se]=1;
		for (i=0;i<=n;i++) dp[i]=f[i];
	}
	for (i=n/2;i>=0;i--) if (dp[i]) return printf("%d\n",i*(i-1)/2+(n-i)*(n-i-1)/2),0;
}


Measured memory_bytes: 9600
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}



int32_t main()
{
   // shuru_krte_hai_bina_kisi_bakchodi_ke();
    int t;
    cin >> t;
    if(t>=30){
        cout<<"Yes"<<"\n";
    }else{
        cout<<"No"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x,c=0;
    cin>>x;
    int y[x+1];
    for (int i=1;i<=x;i++)
        cin>>y[i];
    for (int i=1;i<=x;i++){
        if (i%2==1&&y[i]%2==1)
            c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3652
fn main() {
    proconio::input! {
        n: usize,
        strs: [String; n],
    }
    let mut pos = Vec::new();
    let mut neg = Vec::new();
    for s in strs.iter() {
        let mut mn = 0;
        let mut now = 0;
        for c in s.chars() {
            if c == '(' {
                now += 1;
            } else {
                now -= 1;
            }
            mn = mn.min(now);
        }
        if now >= 0 {
            pos.push((mn, now));
        } else {
            neg.push((mn - now, -now));
        }
    }
    pos.sort_by(|a, b| b.cmp(a));
    neg.sort();
    for (a, b) in &mut neg {
        pos.push((*a - *b, -*b));
    }
    let mut now = 0;
    for (mn, sum) in pos {
        if now + mn < 0 {
            println!("No");
            return;
        }
        now += sum;
    }
    if now == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 70532
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int c = static_cast<int>(s[i]) + n;
        if (c > static_cast<int>('Z')) cout << static_cast<char>(c - 26);
        else cout << static_cast<char>(c);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL


struct node{
  struct node *parent;
  struct node *left;
  struct node *right;
  int key;
};

typedef struct node * Node;

void insert(Node,int);
void PrintInorder(Node );
void PrintPreorder(Node );
Node root,newnode;



main(){

  int n,i,k;
  char T[20];
  
  scanf("%d",&n);
  
  root = malloc(sizeof(struct node));
  
  for( i=0 ; i<n ; i++ ){
    scanf("%s",T);
    
    if( T[0] == 'i'){
      scanf("%d",&k);
    
      if( i != 0)
	insert(root, k);
     
      else 
	root->key = k;
    }
      else{
      PrintInorder(root);
      printf("\n");
      PrintPreorder(root);
      printf("\n"); 
      }
  }
  return 0;
}

void insert(Node T, int k){
  
  Node x,y,z;
  z = malloc(sizeof(struct node));
  z->key =k;
  z->left = z->right = NIL;

  y = NIL;
  x = T;
  while(1){
    y = x;
    if( z->key < x->key )
      x = x->left;
    else 
      x = x->right;

    if( x == NIL )break;
  }
  z->parent =y;
    if( y == NIL )
      T = z;
    else if(z->key < y->key)
      y->left = z;
    else 
      y->right = z;
    
}
 
void PrintInorder(Node T)
{
  if(T != NIL){
     PrintInorder(T->left);
  
  printf(" %d",T->key);
    
   PrintInorder(T->right);
  }
  else return;
   
}
 

void PrintPreorder(Node T){
  if(T != NIL){
    printf(" %d",T->key);
 
    PrintPreorder(T->left);
    PrintPreorder(T->right);
 
  }
  else return ;
}     

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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> height(n);
	std::vector<long long> cost(n);
	for (int i{}; i < n; i++)
		scanf("%d", &height[i]);
	cost[0] = 0;
	cost[1] = std::abs(height[1] - height[0]);
	for (int i{2}; i < n; i++)
		cost[i] = std::min(cost[i - 2] + std::abs(height[i] - height[i - 2]), cost[i - 1] + std::abs(height[i] - height[i - 1]));
	printf("%lld\n", cost.back());

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
bool visited[105];
double solve(double a,double tax){
    int start=0;
    int end=100;
    int ans=0-1;
    while(start<end && start!=end){
        double  mid=start+end;
        mid=ceil(mid/2);
        debug3(start,mid,floor(mid*tax));
        if(floor(mid*tax)==a){
            ans=mid;
            return ans;
        }
        else if(floor(mid*tax)>a) end=mid-1;
        else start=mid+1;
    }
    return ans;
}

int32_t main()
{
fastio;
int t=1;
//in t;
while(t--){
string s;in s;
int q;in q;
bool rev=0;
vector<char> v[2];
while(q--){
    int a;in a;
    if(a==1){
        rev=!rev;
    }
    else{
        int b;in b;char c;in c;
        if(!rev){
            if(b==1) v[0].pb(c);
            else v[1].pb(c);
        }
        else{
            if(b==1) v[1].pb(c);
            else v[0].pb(c);
        }
    }
}
string t;
for(int i=v[0].size()-1;i>=0;i--)
    t+=v[0][i];
t+=s;
for(int i=0;i<v[1].size();i++){
    t+=v[1][i];
}
if(rev) reverse(t.begin(),t.end());
cout<<t<<endl;
}
#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1448
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)



int main() {
    ll n, m;
    
    cin >> n >> m;
    
    if(n == 1 || m == 1){
        if(n == 1 && m == 1){
            cout << 1 << endl;
        }
        else{
            if(n == 1){
                cout << max(0LL, m - 2) << endl;
            }
            else{
                cout << max(0LL, n - 2) << endl;
            }
        }
    }
    else{
        cout << (n - 2) * (m - 2) << endl;
    }
}

Measured memory_bytes: 256
def digit_sum2(num):
    total = 0
    for digit in str(num):
        total += int(digit)
    return total
    
n = input()
l = len(n)
n = int(n)

if n == 10 ** l -1:
    print( 9 * l )
elif 1 <= n <= 9:
    print(n)
else:
    print(max(digit_sum2(n), n // (10 ** (l-1)) - 1 + 9 * (l-1)))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int N,M;
	cin >> N >> M;
	vector<vector<int>>g(N);
	REP(i,M){
		int a,b;
		cin >> a >> b;
		--a;--b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	out("Yes");
	vector<int>ans(N,-1);
	queue<pair<int,int>>que;
	vector<int>dist(N,INF);
	que.push({0,0});
	dist[0] = 0;
	while(!que.empty()){
		auto[cost,now] = que.front();
		que.pop();
		if(dist[now] != cost)continue;
		for(auto e:g[now]){
			if(dist[e] != INF)continue;
			ans[e] = now;
			dist[e] = cost + 1;
			que.push({cost + 1,e});
		}
	}
	FOR(i,1,N){
		out(ans[i] + 1);
	}
}

Measured memory_bytes: 14524
#include<stdio.h>

int main(){
	int a;
	scanf("%d",&a);
	if(a<=99){
		if(a/10==a%10) printf("Yes\n");
		else printf("No\n");
	}
	else if(a<=999){
		if(a/100==a%10) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>

using namespace std;
#define MAX 100
#define NIL (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
int G[MAX][MAX];//图的邻接矩阵
int color[MAX];//节点状态
int n;
int d[MAX];//最小权值
int p[MAX];//父亲节点
void prim(){
    for(int i=0;i<n;i++){
        color[i] = WHITE;
        d[i] = NIL;
        p[i] = -1;
    }
    d[0] = 0;
    while(1){
        int u;
        int mincost = NIL;
        for(int i=0;i<n;i++){//循环找到下一个要加入到T中的
            if(color[i]!=BLACK&&d[i]<mincost){
                mincost = d[i];
                u = i;
            }
        }
        if(mincost==NIL){
            break;
        }
        color[u] = BLACK;
        for(int v=0;v<n;v++){//给相邻顶点的d赋值（与之前的相比较，找到最小的）
            if(color[v]!=BLACK&&G[u][v]!=-1){
                if(G[u][v]<d[v]){
                    d[v] = G[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }


}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>G[i][j];
        }
    }
    prim();
    int sum = 0;
    for(int i=0;i<n;i++){
        sum += d[i];
    }
    cout<<sum<<endl;

    return 0;
}



Measured memory_bytes: 3100
import java.util.*;
import java.util.function.Predicate;

public class Main {

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

    void run() {
        Scanner cin = new Scanner(System.in);
        N = cin.nextInt();
        H = new int[N + 1]; //参照先がオーバーすることがあるので1余計に取る
        dp = new int[N];
        for (int i = 0; i < N; i++){
            H[i] = cin.nextInt();
            dp[i] = -1; //未記録なものは-1としておく
        }
        System.out.println(dfs(0));
    }

    int N;
    int[] H;
    int[] dp;
    //今の場所からのゴールまでの最小コストを返す
    int dfs(int pos) {
        //オーバーしてた場合は、十分大きいコストを返す
        if (pos >= N) return 99999999;
        //ゴールしてたらこれ以上のコストはかからないので、0を返す
        if (pos == N - 1) return 0;
        //すでにdfs(pos)の結果を計算済みであれば、その値を返す
        if(dp[pos] != -1) return dp[pos];
        //途中であれば、1つ進む場合と2つ進む場合を比較し、今後の歩数が少なくて済む方を返す
        int step1 = dfs(pos + 1) + Math.abs(H[pos + 1] - H[pos]);
        int step2 = dfs(pos + 2) + Math.abs(H[pos + 2] - H[pos]);
        //値を返す際に、dp配列に答えを保存する
        return dp[pos] = Math.min(step1, step2);
    }
}



Measured memory_bytes: 71196
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int A, B, K; cin >> A >> B >> K;
  for(int i = A; i <= min(A + K - 1, B); i++){
    cout << i << endl;
  }
  for(int i = max(min(A + K - 1, B) + 1, B - K + 1); i <= B; i++){
    cout << i << endl;
  }
}


Measured memory_bytes: 256
#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 all(a) (a).begin(), (a).end()


int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u) cout << a-1 << ' ' << b << endl;
    else cout << a << ' ' << b - 1<< endl;
}


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

int main() {
  ll a,b,k;
  cin >>a>>b>>k;
  if(a>=k) cout << a-k << " " << b <<endl;
  else if(k>a && k<=a+b) cout << 0 << " " << a+b-k << endl;
  else if(k >a+b) cout << 0 << " " << 0 <<endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a,b)for(int i=a;i<b;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define ll long long
const ll M=1000000007;

string s;
int t[30];

int main(){
	cin>>s;
	rep(i,s.size())t[(int)(s[i]-'a')]=1;

	int in=-1;

	rep(i,26){
		if(!t[i]){
			in=i;
			break;
		}
	}



	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<-1<<endl;
		return 0;
	}

	

	if(in==-1){
		int ns=s.size();
		for(int i=ns-1;i>=0;i--){
			int ma=1000;
			for(int j=i+1;j<ns;j++){
				if(s[j]-'a'>s[i]-'a')ma=min(ma,s[j]-'a');
			}
				
			if(ma!=1000&&ma>s[i]-'a'){
				rep(j,i)cout<<s[j];
				cout<<(char)('a'+ma)<<endl;
				return 0;
			}
		}	
	}	

	else{
		s.push_back('a'+in);
		cout<<s<<endl;
	}	
	return 0;
}


Measured memory_bytes: 256
def solve(w, h, x, y):
    area = w * h / 2.0
    if 2 * x == w and 2 * y == h:
        multi = 1
    else:
        multi = 0
    return area, multi


def main():
    w, h, x, y = (int(z) for z in input().split())
    area, judge = solve(w, h, x, y)
    print("{:.12f} {}".format(area, judge))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N,M=map(int,input().split())
mod=10**9+7

#x以下の素数の列挙   
import math
x=math.floor(math.sqrt(10**9))
L=math.floor(math.sqrt(x))#平方根を求める
Primelist=[i for i in range(x+1)]
Primelist[1]=0#素数でないものは0にする.
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0
Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

#素因数分解
DICT=dict()
i=0
while M!=1:
    if M%Primes[i]==0:
        DICT[i]=DICT.get(i,0)+1
        M=M//Primes[i]
    elif i<len(Primes)-1:
        i+=1
    else:
        DICT[M]=1
        M=1

def Combi2(a,b):#aは大きいが、bは小さいとき
    ANS=1
    for i in range(min(b,a-b)):
        ANS=ANS*(a-i)%mod*pow(b-i,mod-2,mod)%mod

    return ANS%mod


ANS=1
for i in DICT.values():
    ANS=ANS*Combi2(N-1+i,i)%mod

print(ANS)


Measured memory_bytes: 4404
#include<stdio.h>

#define MAX  1000
#define MAX_1 10000


int n, a[MAX], s;
int b[MAX], T[MAX_1 + 1];


int partition(int a[], int p, int r){
  int i, j;
  int t, x;
  x = a[r];
  i = p - 1;

  for( j = p ; j < r ; j++ ){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}
void quickS(int a[], int p, int r){
  int q;
  if(p < r){
    q = partition(a, p, r);
    quickS(a, p, q - 1);
    quickS(a, q + 1, r);
  }
}


int solve(){
  int i, c, S, m, an, v,   ans = 0 ;

  int V[MAX];
  for(i = 0 ; i < n ; i++){
    b[i] = a[i];
    V[i] = 0;
  }

  quickS(b, 0, n - 1);

  for(i = 0 ; i < n ; i++) T[b[i]] = i;
  for(i = 0 ; i < n ; i++){
    if(V[i]) continue;
    c = i;
    S = 0;
    m = MAX_1;
    an = 0;
    while(1){
      V[c] = 1;
      an++;
      v = a[c];

      if(v < m) m = v;

      S += v;
      c = T[v];
      if(V[c]) break;
    }
    if(S + (an -2) * m < m + S + (an + 1) * s) ans += S + (an -2) * m;
    else ans +=  m + S + (an + 1) * s;
  }
  return ans;
}



int main(){
  int i;

  scanf("%d", &n);
  s = MAX_1;
  for(i = 0 ; i < n ; i++){
    scanf("%d", &a[i]);
    if(a[i] < s) s = a[i];
  }

  int ans = solve();
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<ll>v(n);
  rep(i,n)cin >> v[i];
  sort(All(v));
  ll ans = v[n - 1] - v[0];
  for(int i = 0,j = n - 2;i + 1 < j; ++i,--j)ans += v[j] - v[i];
  for(int i = 1,j = n - 1;i + 1 < j;++i,--j)ans += v[j] - v[i];
  if(n & 1)ans += max(v[n / 2 + 1] - v[n / 2],v[n / 2] - v[n / 2 - 1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4056
x1, y1, x2, y2 = gets.split.map(&:to_i)

cal_x = x2 - x1
cal_y = y2 - y1

x3 = x2 - cal_y
y3 = y2 + cal_x

x4 = x3 - cal_x
y4 = y3 - cal_y

puts x3.to_s + " " + y3.to_s + " " + x4.to_s + " " + y4.to_s 

Measured memory_bytes: 1788
/*
Problem:Factors of Factorial 
Algorithm:Violent
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997}; 
int cnt[200];

int main()
{
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		int x=i;
		for(int j=0;j<168;j++){
			if(x==1)break;
			while(!(x%prime[j])){
				x/=prime[j];
				cnt[j]++;
			}
		}
	}
	long long ans=1;
	for(int i=0;i<168;i++){
		if(cnt[i]>0){
			ans=(ans*(cnt[i]+1))%INF;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int,input().split())), reverse=True)

if 0 in A:
    print(0)
    exit()

ans=1

for i in range(N):
    ans = ans * A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 21640
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  std::string n;
  std::cin >> n;

  std::replace(n.begin(), n.end(), '1', '*');
  std::replace(n.begin(), n.end(), '9', '1');
  std::replace(n.begin(), n.end(), '*', '9');

  std::cout << n << std::endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a * b == 15)
    cout << '*' << endl;
  else if(a + b == 15)
    cout << '+' << endl;
  else
    cout << 'x' << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

def cost(state):
    now = 0
    ret = 0
    cnt = 0
    for d, a in enumerate(A):
        if (state & (1 << d)) > 0:
            cnt += 1
            ret += max(0, now + 1 - a)
            now = max(now + 1, a)
        else:
            now = max(now, a)

    return ret if cnt >= K else 10**20

ans = 10**20
for state in range(1 << N):
    ans = min(ans, cost(state))

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    int c=scan.nextInt();
    if(a+b+c>=22){
      System.out.println("bust");
    }else{
      System.out.println("win");
    }
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var kn = Console.ReadLine().Split(' ');
            var k = int.Parse(kn[0]);
            var n = int.Parse(kn[1]);
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var diffamax = k - a[n - 1] + a[0];

            for (int i = 1; i < n; i++)
            {
                diffamax = Math.Max(diffamax, a[i] - a[i - 1]);
            }


            Console.WriteLine(k - diffamax);

            
        }
    }
}



Measured memory_bytes: 34780
import itertools
import numpy

n,m = map(int,input().split(" "))

switchs = []
for i in range(m):
    switchs.append([int(e) for e in input().split(" ")])

on_state = [int(e) for e in input().split(" ")]

switch_connect = numpy.zeros((m,n),dtype="int64")

for k,i in enumerate(switchs):
    for j in i[1:]:
        switch_connect[k,j-1] = 1

ret = 0
for i in itertools.product([0,1],repeat=n):
    result = numpy.dot(switch_connect, numpy.array(i).T)
    result = result%2
    ret += numpy.all(result == on_state)
print(ret)

Measured memory_bytes: 21468
import sys

def solve():
      input = sys.stdin.readline
      X = int(input())
      Count = [1] * (X + 1)
      if X == 1: print(1)
      else:
            ans = 1
            for i in range(2, X + 1):
                  Count[i] += 1
                  ans += Count[i] * i
                  d = i * 2
                  while d <= X:
                        Count[d] += 1
                        d += i
            print(ans)


      return 0

if __name__ == "__main__":
      solve()

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

int main() {
    int64_t N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<int64_t> A(N);
    for(auto &e : A) cin >> e;
    sort(A.begin(), A.end());
    rep(i, N) A[i] += M;
    vector<int64_t> cum(N + 1);
    rep(i, N) cum[i + 1] = cum[i] + A[i];
    int y = N - P;
    auto OK = [&](int x) -> bool {
        if(A[x] + M < A[y]) return false;
        int64_t S = cum[y + 1] - cum[x + 1];
        int64_t D = A[x] * (y - x);
        return S - D <= M * (N - V);
    };
    int l = -1, r = y;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        OK(mid) ? r = mid : l = mid;
    }
    cout << N - r << '\n';
    return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t a,b,c,k,ans; cin>>a>>b>>c>>k;
    if(k%2) ans=b-a;
    else ans=a-b;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long a = scanner.nextLong();
			long b = scanner.nextLong();
			scanner.nextLine();
			System.out.println(result(a - 1) ^ result(b));
		}
	}

	private static long result(long input) {
		long remainder = input % 4L;
		switch ((int) remainder) {
		case 0:
			return input;
		case 1:
			return 1L;
		case 2:
			return input + 1;
		case 3:
		default:
			return 0L;
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  
  int64_t a[3 * N];
  for (int i = 0; i < 3 * N; i++) cin >> a[i];
  
  sort(a, a + 3 * N, greater<int>());
  
  int64_t sum = 0;  
  for (int n = 0; n < N; n++) {
    sum += a[2 * n + 1];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 5884
n = int(input())
a = list(map(int, input().split()))
l = [[] for i in range(n)]

for i in range(n):
    
    l[i] = [a[i], i+1]
    
l.sort()
ans = [0 for i in range(n)]

for i in range(n):
    ans[i] = l[i][1]  

print(*ans)

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

char str[100010];
char str1[200010];
char str2[200010];


int main( int argc, char *argv[] )
{
  int q = 0;
  int f=0;
  int t;
  int ff;
  char c;
  int s1 =0 ;
  int s2 =0 ;
  int i;
  
  scanf( "%s", str );
  scanf( "%d", &q );
  for( i = 0 ; i < q ; i ++ ){
    scanf( "%d", &t );
    if( t == 1 ){
      if( f ) f = 0;
      else f = 1;
    }
    else{
      scanf( "%d %c", &ff, &c );
      if( (f==0 && ff==1) || (f==1 && ff==2) ){
	str1[s1++] = c;
      }
      else{
	str2[s2++] = c;
      }
    }
  }

//printf( "%d %s %s %s\n", f, str1, str, str2 );

  if( f == 0 ){
    int sss;
    for( i = 0 ; i < s1 ; i ++ ){
      printf( "%c", str1[s1-i-1] );
    }
    sss = strlen( str );
    for( i = 0 ; i < sss ; i ++ ){
      printf( "%c", str[i] );
    }
    for( i = 0 ; i < s2 ; i ++ ){
      printf( "%c", str2[i] );
    }
  }
  else{
    int sss;
    for( i = 0 ; i < s2 ; i ++ ){
      printf( "%c", str2[s2-i-1] );
    }
    sss = strlen( str );
    for( i = 0 ; i < sss ; i ++ ){
      printf( "%c", str[sss-i-1] );
    }
    for( i = 0 ; i < s1 ; i ++ ){
      printf( "%c", str1[i] );
    }
  }
}



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

int main(void)
{
    int A, B, C;
    cin >> A >> B >> C;

    if(A%B==0){
        if(C==0)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
        return(0);
    }
    else if(A%2==0 and B%2==0 and C%2!=0){
        cout << "NO" << endl;
        return(0);
    }
    else{
        for(int i{1}; i<100; ++i){
            if((B*i+C)%A==0){
                cout << "YES" << endl;
                return(0);
            }
        }
        cout << "NO" << endl;
        return(0);

    }

}


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

int main() {
  string S;
  cin >> S;

  if (S == "AAB") {
    cout << "Yes" << endl;
  }
 if (S == "ABA") {
    cout << "Yes" << endl;
  }
 else if (S == "BAA") {
    cout << "Yes" << endl;
  }
 else if (S == "ABB") {
    cout << "Yes" << endl;
  }
 else if (S == "BAB") {
    cout << "Yes" << endl;
  }
 else if (S == "BBA") {
    cout << "Yes" << endl;
  } 
 else if (S == "BBB") {
    cout << "No" << endl;
  }
  else if (S == "AAA") {
    cout << "No" << endl;
  } 

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
    int s,n,p,i,j,y;
    double a;
    while(scanf("%d",&p) , p != 0){
        s = 0;
        n = 1;
        for (i = 1;i <= p;i++){
            while(1){
                n++;
                y = 1;
                a = n;
                a = sqrt(a);
                for(j = 2;j <= a;j++){
                    if(!(n % j)){
                        y = 0;
                        break;
                    }
                }
                if(y){
                    s += n;
                    break;
                }
            }
        }
        printf("%d\n" , s);
    }
    return 0;
}

Measured memory_bytes: 600
def bb
    n,m,c = gets.chomp.split(/\s/).map{|x| x.to_i}
    b = gets.chomp.split(/\s/).map{|x| x.to_i}

    s = 0
    for i in 1..n
        a = gets.chomp.split(/\s/).map{|x| x.to_i}

        d = 0
        for j in 0..(a.length-1)
            d += a[j] * b[j]
        end
        s += 1 if d + c > 0
    end

    puts s
end

bb

Measured memory_bytes: 1788
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N;cin>>N;
  int ma=0;
  int ans=0;
  for(int i=0;i<N;i++){
    int a;cin>>a;
    if(a>=ma)ans++;
    ma=max(a,ma);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

vector<int> primes(100001, 0);

void prime_make(){
    // 累積和
    primes[1] = 0;
    primes[2] = 0;
    primes[3] = 1;
    primes[4] = 0;
    primes[5] = 2;
    primes[6] = 0;
    bool is_prime_n;
    bool is_prime_plus1;
    for(int i=7; i<=100000; i+=2){
        int root = sqrt(i);
        is_prime_n = true;
        is_prime_plus1 = true;
        for(int j=2; j<=root; j++){
            if(i%j==0){
                is_prime_n = false;
                break;
            }
            if(((1+i)/2)%j==0){
                is_prime_plus1 = false;
                break;
            }
        }
        if(is_prime_n && is_prime_plus1){
            primes[i] = primes[i-2] + 1;
        }else{
            primes[i] = primes[i-2];
        }
    }
    for(int i=2; i<=100000; i+=2){
        primes[i] = primes[i-1];
    }
}

int main(){
    int q; cin >> q;
    prime_make();
    int l, r;
    REP(i, q){
        cin >> l >> r;
        cout << primes[r] - primes[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <set> 
#define maxn 200005
typedef long long ll;
using namespace std;
string arr[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	cin>>arr[i];
    	sort(arr[i].begin(),arr[i].end());
	}
	sort(arr+1,arr+1+n);
	ll ans=0,now=0;
    for(int i=1;i<=n;i++)
    {
    	if(arr[i]!=arr[i-1])now=0;
    	else now++,ans+=now;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#define N 3

int main(){
    int a[3];
    for(int i=0; i<N; ++i) std::cin>> a[i];

    std::sort(a,a+3);

    for(int i=0; i<N-1; ++i) std::cout << a[i] <<" ";
    std::cout << a[N-1] <<"\n";

}

Measured memory_bytes: 3088