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

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

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

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    cum = [[0]*(W+1) for _ in range(H+1)]
    for i in range(1,H+1):
        for j in range(1,W+1):
            cum[i][j]=cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+int(S[i-1][j-1])
    ans = 2000
    for p in product([0,1],repeat=H-1):
        line = [0]
        p = list(p)
        cnt = sum(p)
        for i in range(1,H):
            if p[i-1]==1:
                line.append(i)
        line.append(H)
        w_s = 0
        w_e = 1
        b = False
        while w_e <= W:
            for i in range(len(line)-1):
                h_s = line[i]
                h_e = line[i+1]
                white = cum[h_e][w_e]+cum[h_s][w_s]-cum[h_e][w_s]-cum[h_s][w_e]
                if white > K:
                    if w_e == w_s+1:
                        b = True
                        break
                    else:
                        w_s = w_e-1
                        cnt += 1
                        break
            if b==True:
                break
            w_e += 1
        else:
            ans = min(ans,cnt)
    return ans
print(solve())

Measured memory_bytes: 43100
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
const int N=2e5+20;
ll f[N],g[N],n,x,y,z;
struct node{
	ll a,b,c;
}a[N];
bool cmp(node a,node b){
	return a.a-a.b<b.a-b.b;
}
multiset<ll> s;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	while(cin>>x>>y>>z){
		ll res=0;
		n=x+y+z;
		s.clear();
		for(int i=1;i<=n;i++){
			cin>>a[i].a>>a[i].b>>a[i].c;
			res+=a[i].c;
			a[i].a-=a[i].c,a[i].b-=a[i].c,a[i].c=0;
		}
		sort(a+1,a+1+n,cmp);
		ll sum=0;
		for(int i=1;i<=n;i++){
			sum+=a[i].b;
			s.insert(a[i].b);
			if(s.size()>y){
				sum-=*s.begin();
				s.erase(s.begin());
			}
			f[i]=sum;
		}
		s.clear();
		sum=0;
		for(int i=n;i>=1;i--){
			sum+=a[i].a;
			s.insert(a[i].a);
			if(s.size()>x){
				sum-=*s.begin();
				s.erase(s.begin());
			}
			g[i]=sum;
		}
		ll ans=0;
		for(int i=y;i<=n-x;i++)
		ans=max(ans,res+f[i]+g[i+1]);
		cout<<ans<<endl;	
	}
	//system("pause");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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 sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;

	rep(i,0,ty-sy)cout << "U";
	rep(i,0,tx-sx)cout << "R";
	rep(i,0,ty-sy)cout << "D";
	rep(i,0,tx-sx+1)cout << "L";
	rep(i,0,ty-sy+1)cout << "U";
	rep(i,0,tx-sx+1)cout << "R";
	cout << "D";
	cout << "R";
	rep(i,0,ty-sy+1)cout << "D";
	rep(i,0,tx-sx+1)cout << "L";
	cout << "U" << endl;
	
	return  0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans=0,w,m=1e10;
  cin >> n;
  rep(i,n) {
    cin >> w;
    m=min(w,m);
    if(m>=w)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll cnt = 1;

    ll s;cin>>s;
    map<ll,ll> mp;
    while(1){
        if(mp[s]){
            cout<<cnt<<endl;
            return 0;
        }
        mp[s]++;
        s = (s%2==0) ? s/2: 3*s+1;
        cnt++;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num = 0;
    cin >> num;
    int x, y;
    cin >> x >> y;

    vector<int> map(num);
    for(int i = 1; i <= num; i++) {
        for(int j = i+1; j <= num; j++) {
            int res = j-i;
            res = min(res,
                abs(x-i) + 1 + abs(y-j)
            );
            map[res]++;
        }
    }
    for(int k = 1; k <= num-1; k++) {
        cout << map[k] << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
void lcs(string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
   int index = L[m][n]; 
   char lcs[index+1]; 
   lcs[index] = '\0';
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;     
      } 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout<< lcs; 
} 
int main()
{
	string a, b;
	cin>>a>>b;
	lcs(a,b,a.size(),b.size());
	return 0;
}

Measured memory_bytes: 35456
h,w = map(int,input().split())
coin = [list(map(int,input().split())) for i in range(h)]
ans = []
c = 0
for i in range(h):
  for j in range(w-1):
    if coin[i][j] % 2:
      coin[i][j+1] += 1
      ans.append([i+1,j+1,i+1,j+2])
      c += 1

for k in range(h-1):
  if coin[k][w-1] % 2:
    coin[k+1][w-1] += 1
    ans.append([k+1,w,k+2,w])
    c += 1
    
print(c)
for i in range(c):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])
      


Measured memory_bytes: 30256
S = input()
if(S=='SUN'):
    print('7')
elif(S=='MON'):
    print('6')
elif(S=='TUE'):
    print('5')
elif(S=='WED'):
    print('4')
elif(S=='THU'):
    print('3')
elif(S=='FRI'):
    print('2')
elif(S=='SAT'):
    print('1')



Measured memory_bytes: 3060
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(N)]
col = [[0]*3 for i in range(C)]
for i in range(N):
    for j in range(N):
        p = c[i][j]-1
        for k in range(C):
            col[k][(i+j)%3] += D[p][k]
ans = 10**18
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if i == k or j == k:
                continue
            ans = min(ans, col[i][0] + col[j][1] + col[k][2])
print(ans)

Measured memory_bytes: 46428
#include<bits/stdc++.h>
using namespace std;
long long n;
long long ans;
vector<long long> a;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	long long num=n;
	for (long long i=1;i<=sqrt(num);i++)//核心代码
	{
			if (num%i==0)//当num/i没有余数时，说明i是num的一个质数
			{
				if(i!=1&&num/(i-1)==num%(i-1))
				//{
				//	cout<<i-1;
				//}
					ans+=i-1;
				if(num/i!=1&&num/(num/i-1)==num%(num/i-1))
				//{
				//	cout<<num/i-1;
				//}
					ans+=num/i-1;
			}
		//然后跳出，重新来，此时num变了，i也变成2了，因为重新开始
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		long min = Math.min(N, M);
		long max = Math.max(N, M);
		long sum = 1;
		for(long i = 2; i <= min; i++) {
			sum = sum * i % 1000000007;
		}
		
		if(N == M) {
			System.out.println(((sum * sum) % 1000000007) * 2 % 1000000007);
		} else if(Math.abs(N - M) == 1) {
			System.out.println(sum * ((sum * max) % 1000000007) % 1000000007);
		} else {
			System.out.println(0);
		}
	}
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n + 2, 0);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    long long s = 0;
    for (int i = 1; i <= n + 1; ++i) s += abs(a[i] - a[i - 1]);
    for (int i = 1; i <= n; ++i) {
        long long p = s;
        p -= abs(a[i] - a[i - 1]);
        p -= abs(a[i + 1] - a[i]);
        p += abs(a[i + 1] - a[i - 1]);
        cout << p << '\n';
    }
}


Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 果物の数
		int n = sc.nextInt();
		// 購入する果物の数
		int k = sc.nextInt();

		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		// sort
		Arrays.parallelSort(p);

		int ans = 0;
		for (int i = 0; i < k; i++) {
			ans += p[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 38968
#include <stdio.h>

int main(void){
	char s[14] = {'\0'};
	scanf("%s",s);
	for(int a = 13; a >= 0; a--){
		s[a] = s[a-1];
		if(a == 4){
			s[a] = ' ';
			break;
		}
	}
	printf("%s\n",s);
	return 0;
}


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

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

  string str1 = "",str2 = "";
  int T = 0;
  for(int i = 0;i < Q;i++) {
    int t;
    cin >> t;
    if(t == 1) {
      T++;
    }else {
      int f;
      string ch;
      cin >> f >> ch;
      if(T % 2 == 0) {
        if(f == 1) str1 = ch+str1;
        else  str2 += ch;
      }else {
        if(f == 2) str1 = ch+str1;
        else  str2 += ch;
      }
    }
  }

  if(T%2!=0) {
    reverse(S.begin(),S.end());
    reverse(str1.begin(),str1.end());
    reverse(str2.begin(),str2.end());
    if(!str1.size() && !str2.size()) cout << S << endl;
    else if(str1.size() == 0) cout << str2+S << endl;
    else if(str2.size() == 0) cout << S+str1 << endl;
    else cout << str2+S+str1 << endl;
  }else {
    if(!str1.size() && !str2.size()) cout << S << endl;
    else if(str1.size() == 0) cout << S+str2 << endl;
    else if(str2.size() == 0) cout << str1+S << endl;
    else cout << str1+S+str2 << endl;
  }
  

}


Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll cntl[200000],cntr[200000];

int main() {
  ll n,x,ans=0;
  cin >> n;
  for(ll i=1;i<=n;i++){
    cin >> x;
    if(i+x<n) cntl[i+x]++;
    if(i-x>1) cntr[i-x]++;
  }
  for(int i=2;i<n;i++) ans += cntl[i]*cntr[i];
  cout << ans << endl;
}


Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    ll x,y;
    cin >> x >> y;
    if (x>=0&&y>0&&x<y){
        cout << abs(x-y) << endl;
    }
    else if (x>0&&y>0&&x>y){
        cout << abs(x-y)+2 << endl;
    }
    else if (x<0&&y<=0&&x<y){
        cout << abs(x-y) << endl;
    }
    else if (x<0&&y<=0&&x>y){
        cout << abs(x-y)+2 << endl;
    }
    else if ((x>=0&&y<=0)||(x<0&&y>=0)){
        cout << abs(abs(x)-abs(y))+1 << endl;
    }
    else if (x>0&&y==0){
        cout << abs(x)+1 << endl;
    }
}

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



#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 repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  map<ll,ll>ma;
  rep(i,n){
    ll a;cin>>a;
    ma[a]++;
  }
  rep(i,m){
    ll b,c;cin>>b>>c;
    ma[c]+=b;
  }
  ll res=0;

  for(auto itr=ma.rbegin();itr!=ma.rend();itr++){
    //cout<<(*itr).first<<endl;
    auto tp=*itr;
    if(n>tp.second){
      n-=tp.second;
      res+=tp.first*tp.second;
    }
    else{
      res+=tp.first*(n);
      break;
    }
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 12800
import sys
import heapq
from collections import deque

# sys.setrecursionlimit(100001)
INF = sys.maxsize


# ===CODE===
def main():
    a_hp,a_atc,b_hp,b_atc = map(int, input().split())

    while True:
        b_hp -= a_atc

        if b_hp<1:
            print("Yes")
            exit(0)

        a_hp -= b_atc
        if a_hp<1:
            print("No")
            exit(0)

if __name__ == '__main__':
    main()


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

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        Stack<Integer> trains=new Stack<>();
        while (sc.hasNext()) {
            int n=sc.nextInt();
            if(n==0){
                System.out.println(trains.pop());
            }else{
                trains.push(n);
            }
        }
    }
}


Measured memory_bytes: 26200
S=input()
N=len(S)
r_S=S[::-1]
c1=int((N-1)/2)
c2=int((N+3)/2)
S1=S[:c1]
r_S1=S1[::-1]
S2=S[(c2-1):]
r_S2=S2[::-1]


#kaibun hantei
if S==r_S and S1==r_S1 and S2==r_S2:
  print("Yes")
else:
  print("No")

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

void solve(){
	
	int n,t ;
	cin>>n>>t ;

	if(t==1)
	{
		cout<<0 ;
		return ;
	}

	int sock=0 ;
	int step=0 ;

	while(true){

		sock+=n ;
		step++ ;

		if(sock>=t){
			cout<<step ;
			return ;
		}

		sock-=1 ;

	}
	

}	

int main(){


	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 3588
package main

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

var (
	c string
)

func main() {
	readVariables()
	fmt.Println(string(int(c[0]) + 1))
}

func readVariables() {
	c = nextStr()
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  ll N, M; cin >> N >> M;
  vector<ll> A(M);
  for (auto& a : A) { cin >> a; }
  auto sum = std::accumulate(A.begin(), A.end(), 0LL);
  if (sum > N) {
    cout << -1 << CRLF;
  } else {
    cout << N-sum << CRLF;
  }
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int h, w; cin >> h >> w;
	vector<string> ss(h);
	vector<vector<string>> s(h, vector<string>(w));
	int cnt_in = 0,cnt_out=0;
	for (int i = 0; i < h; i++) {
		cin >> ss[i];
	}
	string z;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			z = ss[i];
			s[i][j] = z[j];
			if (z[j] == '#') cnt_in++;
		}
	}
	int temp;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			temp = 0;
			if (s[i][j] == "#") {
				//up
				if (i > 0) {
					if (s[i - 1][j] == "#") temp++;
				}
				
				//down
				if (i < h-1) {
					if (s[i + 1][j] == "#") temp++;
				}
				
				//right
				if (j < w-1) {
					if (s[i][j + 1] == "#") temp++;
				}
				
				//left
				if (j > 0) {
					if (s[i][j-1] == "#") temp++;
				}
				

				if (temp >0) cnt_out++;
			}
		}
	}
	if (cnt_in == cnt_out)cout << "Yes";
	else cout << "No";

	cout << endl;
	return 0;
}

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

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

string res[6] = {"1:", "2:", "3:", "4:", "5:", "6:"};

int main(void){
	int i, j, n;
	double h;
	scanf("%d", &n);
	for(;n--;){
		scanf("%lf", &h);
		rep(i, 5)if(h < 165.0 + (double)i * 5.0){
			res[i] += "*";
			break;
		}
		if(i == 5)res[5] += "*";
	}
	rep(i, 6)cout << res[i] << endl;
}

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

int main(){

  int N,i;
    int ans = 0;
  vector<int> A(N);
  vector<int> B(N-1);
  cin >> N;
  for(i=0;i<N-1;i++)  cin >> B.at(i);
  
  for(i=0;i<N;i++){
    if(i==0) A.at(i)=B.at(i);
    else if(i==N-1) A.at(i)=B.at(N-2);
    else  A.at(i) = min(B.at(i-1), B.at(i));  
  }
  

  for(i=0;i<N;i++){
    ans += A.at(i);
  }
    if(N==2){
    cout << B.at(0)*2;
  }
  else 
  cout << ans;
}

Measured memory_bytes: 512
a , b , c =map(int,input().split())
p = [i for i in range(1,a)]
k = c
while True:
    k = (k + b) % a
    if k == 0:
        print("YES")
        exit()
    elif p.count(k) == 0:
        print("NO")
        exit()
    elif p.count(k) == 1:
        p.remove(k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define maxn 200020
using namespace std;

int n, a[maxn], m, b[maxn], k;
int main(){
	int x, y, z;
	scanf("%d%d%d", &n, &m, &k);
	int mia = maxn, mib = maxn;
	rep(i, 1, n) scanf("%d", a + i), mia = min(mia, a[i]);
	rep(i, 1, m) scanf("%d", b + i), mib = min(mib, b[i]);
	int res = mia + mib;
	rep(i, 1, k){
		scanf("%d%d%d", &x, &y, &z);
		res = min(res, a[x] + b[y] - z);
	} 
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NL "\n"

int main()
{IOS;string n;int i,d=0;
cin>>n;
for(i=0;n[i]!=0;i++)
    d+= n[i]-'0';
if(d%9==0)
    cout<<"Yes"<<NL;
else cout<<"No"<<NL;}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double l[8];

double f(double v,vector<double> L){
	double sum = 0;
	for(int i = 0 ; i < L.size() - 1 ; i++){
		double t = v / L[i] / L[i+1];
		sum += acos(t);	
	}
	return sum;
}
double calc(double v,vector<double> L){
	double sum = 0;
	for(int i = 0 ; i < L.size() - 1 ; i++){
		double t = v / L[i] / L[i+1];
		
		sum += sin(acos(t)) * L[i] * L[i+1] / 2.0;
	}
	return sum;
}
int main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++) cin >> l[i];
	
	double ans = 0;
	for(int i = 0 ; i < (1<<N) ; i++){
		vector<double> L;
		for(int j = 0 ; j < N ; j++)
			if( i >> j & 1 ) L.push_back(l[j]);
		if( L.size() < 3 ) continue;
		
		sort(L.begin(),L.end());
		do{
			L.push_back(L.front());
			double s = 1e18;
			for(int j = 0 ; j < L.size() - 1 ; j++)
				s = min(s,L[j] * L[j+1]);
			double le = -2*s , ri = 2*s;
			for(int k = 0 ; k < 128 ; k++){
				double mi = (le+ri) / 2.;
				if( f(mi,L) < 2 * PI ){
					ri = mi;
				}else{
					le = mi;
				}
			}
			//cout << f(le,L) << endl;
			ans = max(ans,calc(le,L));
			L.pop_back();
		}while(next_permutation(L.begin(),L.end()));
	}
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 3732
(let* ((land-num (read))
       (request-num (read))
       (lands (make-array (1+ land-num))))
  (loop repeat request-num
        for land1 = (read)
        for land2 = (read)
        do (setf (aref lands land2) (max land1 (aref lands land2))))
  (loop with ans = 0
        for i from 1 upto land-num
        do (and (not (= 0 (aref lands i)))
                (= (aref lands (aref lands i)) ans)
                (incf ans))
           (setf (aref lands i) ans)
        finally (format t "~A~%" ans)))

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

int main(){
  string S;
  int price=700;
  cin >> S;
  
  if (S.at(0)=='o'){
    price+=100;
  }
  if (S.at(1)=='o'){
    price+=100;
  }
  if (S.at(2)=='o'){
    price+=100;
  }
  
  cout << price <<endl;
}

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

int main() {
  string s;cin>>s;
  ll k; cin>>k;
  ll c=0;
  char a='1';
  for(auto & ch : s) {
    if(ch=='1')c++;
    else {
      a=ch;
      break;
    }
  }
  if(k<=c) {
    cout<<"1"<<endl;
  } else {
    cout<<a<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{

    lint n;
    scanf("%lld", &n);

    std::vector<lint> dam(n);
    std::vector<lint> mountains(n);

    for (int i = 0; i < n; ++i)
    {
        lint a;
        scanf("%lld", &a);

        dam[i] = a;
    }

    lint mountain_1 = 0;
    lint sign = 1;
    for (int i = 0; i < n; ++i)
    {
        mountain_1 = mountain_1 + dam[i] * sign;
        sign *= -1;
    }

    mountains[0] = mountain_1;

    for (int i = 1; i < n; ++i)
    {
        mountains[i] = 2 * dam[i - 1] - mountains[i - 1];
    }

    for (int i = 0; i < n; ++i)
    {
        printf("%lld ", mountains[i]);
    }

    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int a[N];

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    map<int, int> A, B;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        A[a[i] - i]++;
        B[-a[i] - i]++;
    }
    int ans = 0;
    for (auto i: A) {
        ans += i.se * B[i.fi];
    }
    cout << ans;
}


Measured memory_bytes: 39380
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    vector<ll>d(n),c(n);
    rep(i,n)cin >> d[i] >> c[i];   
    vector<ll>p(n);
    ll s = 0;
    rep(i,n){
        int k = d[i];
        int L = 1;
        ll x = 0;
        int tmp = d[i];
        while(1){
            if(L!=1&&tmp==d[i])break;
            L++;
            x++;
            tmp += d[i];
            if(tmp>=10){
                x++;
                tmp = (tmp%10)+1;
            }
        }
        L--;

        s += ((c[i]-1)/L)*x;
        c[i] -= ((c[i]-1)/L)*L;
        tmp = d[i];
        while(c[i]!=1){
            c[i]--;
            s++;
            tmp += d[i];
            if(tmp>=10){
                s++;
                tmp = (tmp%10)+1;
            }
        }
        p[i] = tmp;
    }
    // cerr << s << endl;
    // rep(i,n){
    //     cerr << p[i] << " ";
    // }
    // cerr << endl;
    int k = p[0];
    rep(i,n-1){
        s++;
        k += p[i+1];
        if(k>=10){
            s++;
            k = (k%10)+1;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 4992
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		int n = a.length();
		String ans = "";
		for(int i=0;i<n;i++){
			ans += "x";
		}
		System.out.println(ans);
		// your code goes here
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

bool wordcheck(string w,string t){
    int lw=w.length(),lt=t.length();
    if(lw!=lt){
        return false;
    }
    else{
        for(int i=0;i<lw;i++){
            if(w[i]!=t[i]&&w[i]-32!=t[i]){
                return false;
            }
        }
    }
    return true;
}

int main(void){
    
    string w,t;
    
    cin>>w;
    
    int cnt;
    
    while(1){
        cin>>t;
        if(t=="END_OF_TEXT") break;
        
        if(wordcheck(w,t))cnt++;
    }
    
    cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 3176
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
vector<int> calc(long long a){
	if(a==1){
		return vector<int>(2,1);
	}
	if(a==2){
		vector<int>ret;
		ret.push_back(1);
		ret.push_back(2);
		ret.push_back(2);
		ret.push_back(1);
		return ret;
	}
	vector<int>tmp=calc((a-1)/2);
	vector<int>ret;
	int mv=0;
	for(int i=0;i<tmp.size();i++)mv=max(mv,tmp[i]);
	if(a%2==1){
		ret.push_back(mv+1);
		for(int i=0;i<tmp.size()/2;i++)ret.push_back(tmp[i]);
		ret.push_back(mv+1);
		for(int i=0;i<tmp.size()/2;i++)ret.push_back(tmp[tmp.size()/2+i]);
	}else{
		ret.push_back(mv+2);
		ret.push_back(mv+1);
		for(int i=0;i<tmp.size()/2;i++)ret.push_back(tmp[i]);
		ret.push_back(mv+1);
		for(int i=0;i<tmp.size()/2;i++)ret.push_back(tmp[tmp.size()/2+i]);
		ret.push_back(mv+2);
	}
	return ret;
}
//549,755,813,888
int main(){
	long long a;
	scanf("%lld",&a);
	vector<int>ret=calc(a);
	printf("%d\n",(int)(ret.size()));
	for(int i=0;i<ret.size();i++){
		if(i)printf(" ");
		printf("%d",ret[i]);
	}
	printf("\n");
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let n: i32 = {
        let mut n = String::new();
        io::stdin().read_line(&mut n).unwrap();
        n.trim_right().to_owned().trim().parse().unwrap()
    };
    let mut ans = 0;
    for i in 0..n {
        ans += n - i;
    }
    print!("{}", ans);
}


Measured memory_bytes: 4352
N = input()
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = B[A[0] - 1]
for i in range(1, len(A)):
    ans += B[A[i] - 1]
    if A[i - 1] == A[i] - 1:
        ans += C[A[i - 1] - 1]
print(ans)


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(H: int):
    ans = 1
    x = 1
    while H != 1:
        H = H // 2
        x *= 2
        ans += x
    print(ans)
        


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    solve(H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>


using namespace std;

int main() {


	int a, b, c;

	cin >> a >> b >> c;


	if ((a != b && b != c && c != a) || (a == b && b == c)) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long dp[87];
long long recFn(int i){
   if( i ==0) return 2;
   if(i ==1) return 1;
   if(dp[i] != -1) return dp[i];
   dp[i] = recFn(i-1) + recFn(i-2);
   return dp[i];
}

int main(){
  for(int i=0;i<87;i++)
    dp[i]=-1l;
  dp[0]=2;
  dp[1]=1;
  int in;
  cin>>in;
  long long cnt=recFn(in);
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    agc039a()
}

fun agc039a() {
    val s = readLine()!!
    val k = readLine()!!.toLong()

    if (s.length == 1) return println(k / 2L)

    var lastChar: Char? = null
    val charCount = mutableListOf<Long>()
    for (i in s.indices) {
        if (lastChar != null && s[i] == lastChar) {
            val last = charCount[charCount.lastIndex]
            charCount.removeAt(charCount.lastIndex)
            charCount.add(last + 1L)
        } else {
            charCount.add(1L)
            lastChar = s[i]
        }
    }

    val inside = charCount.map { it / 2L }.sum()

    for (i in s.indices) {
        if (lastChar != null && s[i] == lastChar) {
            val last = charCount[charCount.lastIndex]
            charCount.removeAt(charCount.lastIndex)
            charCount.add(last + 1L)
        } else {
            charCount.add(1L)
            lastChar = s[i]
        }
    }

    val between = charCount.map { it / 2L }.sum() - inside

    for (i in s.indices) {
        if (lastChar != null && s[i] == lastChar) {
            val last = charCount[charCount.lastIndex]
            charCount.removeAt(charCount.lastIndex)
            charCount.add(last + 1L)
        } else {
            charCount.add(1L)
            lastChar = s[i]
        }
    }

    val between2 = charCount.map { it / 2L }.sum() - between - inside

    val answer = inside + if (between == between2) {
        between * (k - 1L)
    } else {
        (between * Math.ceil((k - 1L).toDouble() / 2) + between2 * Math.floor((k - 1).toDouble() / 2)).toLong()
    }

    println(answer)
}


Measured memory_bytes: 33620
from itertools import product
A, B, Q = map(int, input().split())
S, T, X = [], [], []

for _ in range(A):
  S.append(int(input()))
  
for _ in range(B):
  T.append(int(input()))

for _ in range(Q):
  X.append(int(input()))
  
Xs = sorted(X)

pos = 0
sl, tl = -1e18, -1e18
sr, tr = S[0], T[0]
si, ti, xi = 0, 0, 0 # index

XQ = {} # key=X,value=(x,sl,sr,tl,tr)を格納

for _ in range(int(5e5)):
  pos = min(sr,tr,Xs[xi]) 
  if pos == sr:
    sl = sr
    si += 1
    sr = S[si] if si < A else 1e18
  elif pos == tr:
    tl = tr
    ti += 1
    tr = T[ti] if ti < B else 1e18
  else:
    XQ[Xs[xi]] = [Xs[xi], sl, sr, tl, tr]
    xi += 1
    if xi >= Q:
      break

for i in range(Q):
  x, sl, sr, tl, tr = XQ[X[i]]
  sl, sr, tl, tr = sl-x, sr-x, tl-x, tr-x
  ans = 1e18
  ans = min(ans, abs(sl) + abs(sl-tl))
  ans = min(ans, abs(sl) + abs(sl-tr))
  ans = min(ans, abs(sr) + abs(sr-tl))
  ans = min(ans, abs(sr) + abs(sr-tr))
  ans = min(ans, abs(tl) + abs(tl-sl))
  ans = min(ans, abs(tl) + abs(tl-sr))
  ans = min(ans, abs(tr) + abs(tr-sl))
  ans = min(ans, abs(tr) + abs(tr-sr))
  print(ans)

Measured memory_bytes: 147800
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int
#define Vec vector


template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	string s, t;
	cin >> s >> t;
	
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	
	cout << (s < t ? "Yes" : "No") << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, K; cin >> N >> K;
    vl a(N), acc(N+1, 0);
    REP(i, N){
        cin >> a[i]; acc[i+1] = acc[i] + a[i];
    }
    vl s;
    REP(i, N) FOR(j, i+1, N+1){
        s.pb(acc[j]-acc[i]);
    }
    ll ans = 0;
    for (int i = 45; i >= 0; i--) {
        ll cnt = 0;
        REP(j, s.size()){
            if(s[j] >> i & 1ll) cnt++;
        }
        if(cnt < K){
            continue;
        }
        else{
            ans += 1ll << i;
            vl sn;
            REP(j, s.size()){
                if(s[j] >> i & 1ll) sn.pb(s[j]);
            }
            s.swap(sn);
            vector<ll>().swap(sn);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll a[110000];
int main(){
    ll a,b,ans=1,p=1;
    cin>>a>>b;
    cout<<a*b;
   
}

Measured memory_bytes: 3632
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a>b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a<b) a = b; }

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int A[400020], nxt[400020], idx[200020];
int a[60][200020];//a[k][i]=A[i]の数字を先頭とする2^k個のブロックの要素数
int N, K;
int func(int k, int i) {
	if (a[k][i] > 0)return a[k][i];
	int res = func(k - 1, i) + func(k - 1, (i + func(k - 1, i)) % N);
	a[k][i] = res;
	return res;
}

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

	cin >> N >> K;
	REP(i, N) {
		cin >> A[i]; A[i + N] = A[i];
	}

	REPR(i, N * 2 - 1) {
		nxt[i] = idx[A[i]];
		if (i < N) {
			a[0][i] = nxt[i] - i + 1;
		}
		idx[A[i]] = i;
	}

	ll pos = 0;
	while (pos < (N)*(K-1)) {	
		REP(k, 60) {
			if (pos+func(k, pos%N) > N*K) {
				pos = pos+func(k - 1, pos%N);
				break;
			}
		}
	}
	pos %= N;
	REP(i, N) {
		nxt[i] %= N;
	}
	vector<int>ans;
	for (int i = pos; i < N; i++) {
		if (nxt[i] <= i) {
			ans.pb(A[i]);
		}
		else {
			i = nxt[i];
		}
	}
	REP(i, ans.size()) {
		pe(ans[i]);
	}cout << endl;
}


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

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

int n, k;
vector <iii> seq;

int main()
{
    scanf("%d %d", &n, &k);
    if (k > (n + 1) / 2) printf("-1\n");
    else {
        int fir = n - (n + 1) / 2;
        for (int i = 0; i < n; i++) {
            seq.push_back(iii(i + n + fir, ii(i, n + fir)));
            fir = (fir + 1) % n;
        }
        sort(seq.begin(), seq.end());
        for (int i = 0; i < seq.size(); i++)
            printf("%d %d %d\n", k + seq[i].second.first, k + seq[i].second.second, k + 2 * n + i);
    }
    return 0;
}


Measured memory_bytes: 3572
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= (i+1)

a.sort()
ans = 0
b = a[n//2]
for i in range(n):
    ans += abs(a[i]-b)
if n%2 == 0:
    ans2 = 0
    b2 = a[n//2 - 1]
    for i in range(n):
        ans2 += abs(a[i]-b2)

if n%2 != 0:
    print(ans)
else:
    print(min(ans,ans2)) 

Measured memory_bytes: 31020