akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"Case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vint a(n), b(n);
	rep(i, n)	cin >> a[i] >> b[i];
	vector<tuple<ll, ll, ll>> dat(n);
	rep(i, n)	dat[i] = mt(a[i] - b[i], a[i], b[i]);
	sort(all(dat));
	ll ret = 0;
	int s = 0;
	while (s < dat.size() && get<0>(dat[s]) < 0) {
		ret += get<2>(dat[s]);
		s++;
	}
	if (ret == 0) {
		cout << 0 << endl;
	}
	else {
		while (get<0>(dat[s]) == 0) {
			ret += get<2>(dat[s]);
			s++;
		}
		vector<ll> bb;
		while (s < dat.size()) {
			bb.push_back(get<2>(dat[s]));
			s++;
		}
		sort(all(bb));
		srep(i, 1, bb.size())	ret += bb[i];
		cout << ret << endl;
	}
	return 0;
}

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

#define endl '\n'

using namespace std;

struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <int mod> 
long long fast_pow(long long x, int deg)
{
	long long ans = 1, y = x;
	while (deg)
	{
		if (deg & 1)
			ans = ans * y % mod;

		deg >>= 1; 
		y = y * y % mod;
	}

	return ans; 
}


long long n, a, b;
void read()
{
	cin >> n >> a >> b;
}

void solve()
{
	if (abs(a-b) % 2 == 0)
		cout << abs(a-b) / 2 << endl; 

	else 
	{
		if (a > b)
			swap(a, b);

		cout << min(a + (b-a-1) / 2, n - b + 1 + (b - a - 1) / 2) << endl; 
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	read();
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    lint k;
    cin >> k;
    lint n = s.size();
    for (int i = 0; i < n; ++i) {
        if (s[i] != 'a' && 'z' + 1 - s[i] <= k) {
            k -= ('z' - s[i]) + 1;
            s[i] = 'a';
        }
    }
    k %= lint('z' + 1 - 'a');
    s[n - 1] += k;
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,ans=0;cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin>>s[i];
  for(int i=0;i<h;i++) for(auto c:s[i]) ans+=(c=='#');
  if(ans==h+w-1)puts("Possible");
  else puts("Impossible");
}

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

int main(){
  int n;
  cin>>n;
  
  string s = "No";
  
  for(int i = 0; i<26 ; i++){
    for(int j = 0; j<15 ; j++){
      if(n == 4*i + 7*j)
      s = "Yes";
    }
  }
  cout<<s<<endl;
  
}
      
      

Measured memory_bytes: 256
N = int(input())
X = list(input())
P = X.count("1")
if P != 1:
    P1 = 0
    P2 = 0
    for i in range(N):
        if X[i] == "1":
            P1 += pow(2,N-i-1,P-1)
            P1 %= P-1
            P2 += pow(2,N-i-1,P+1)
            P2 %= P+1
    for i in range(N):
        count = 1
        if X[i] == "0":
            cur = P2+pow(2,N-i-1,P+1)
            cur %= P+1
        else:
            cur = P1-pow(2,N-1-i,P-1)
            cur %= P-1
        while cur > 0:
            mod = bin(cur).count("1")
            cur %= mod
            count += 1
        print(count)
else:
    P2 = 0
    for i in range(N):
        if X[i] == "1":
            P2 += pow(2,N-i-1,P+1)
    for i in range(N):
        count = 1
        if X[i] =="1":
            print(0)
        else:
            cur = P2+pow(2,N-i-1,P+1)
            cur %= P+1
            while cur > 0:
                mod = bin(cur).count("1")
                cur %= mod
                count += 1
            print(count)

Measured memory_bytes: 89216
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<ll> x(5,0);
    for(int i = 0; i < 3; i++){
        ll a,b;
        cin >> a >> b;
        x[a]++;
        x[b]++;
    }

    for(int i = 1; i < 5; i++){
        if(x[i] > 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}

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

namespace ConsoleApp1
{
    static class CLower
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var hList = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            int moveCount = 0;
            int maxMoveCount = 0;
            for (int i = 0; i < n - 1; i++)
            {
                if (hList[i] < hList[i + 1])
                {
                    maxMoveCount = Math.Max(maxMoveCount, moveCount);
                    moveCount = 0;
                    continue;
                }
                moveCount++;
            }

            maxMoveCount = Math.Max(maxMoveCount, moveCount);

            Console.WriteLine(maxMoveCount);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 28636
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll maxP = 100000 * 10000;

int n, k;
ll T[100000];

int check(ll p) {
  int i = 0;
  for (int j = 0; j < k; j++) {
    ll s = 0;
    while (s + T[i] <= p) {
      s += T[i];
      i++;
      if (i == n) return n;
    }
  }
  return i;
};

int solve() {
  ll left = 0;
  ll right = maxP;
  ll mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    int v = check(mid);
    if (v >= n) {
      right = mid;
    } else {
      left = mid;
    }
  }
  return right;
};

int main() {
  cin >> n >> k;
  int w[n];
  for (int i = 0; i < n; i++) {
    cin >> T[i];
  }
  ll ans = solve();
  cout << ans << endl;
};



Measured memory_bytes: 3892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
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();
}

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

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

  int r;
  cin >> r;

  cout << r * r << endl;

  return 0;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
ans = 10**20
(N-K+1).times do |i|
    a = as[i]
    b = as[i+K-1]
    if b <= 0
        result = a.abs
    elsif a >= 0
        result = b.abs
    else
        result = a.abs + b.abs
        result += a.abs < b.abs ? a.abs : b.abs
    end
    ans = result if ans > result
end
puts ans


Measured memory_bytes: 10500
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#define rg register
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) ((a)>0?(a):-(a))
#define ll long long 
#pragma GCC optimize(3)
#pragma -fcrossjumping
#pragma -fdefer-pop
#pragma -fmerge-constans
#pragma -fthread-jumps
#pragma -floop-optimize
#pragma -fif-conversion
#pragma -fif-conversion2
#pragma -fdelayed-branch
#pragma -fguess-branch-probability
#pragma -fcprop-registers
#pragma -fforce-mem
#pragma -foptimize-sibling-calls
#pragma -fstrength-reduce
#pragma -fgcse
#pragma -fcse-follow-jumps
#pragma -frerun-cse-after-loop
#pragma -fdelete-null-pointer-checks
#pragma -fextensive-optimizations
#pragma -fregmove
#pragma -fschedule-insns
#pragma -fsched-interblock
#pragma -fcaller-saves
#pragma -fpeephole2
#pragma -freorder-blocks
#pragma -fstrict-aliasing
#pragma -funit-at-a-time
#pragma -falign-functions
#pragma -fcrossjumping
#pragma -finline-functions
#pragma -fweb
using namespace std;
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
ll a,b;
int main()
{
	a=read(),b=read();
	if(a<b) swap(a,b);//b<a   x-b=a-x
	if((a+b)%2!=0)
	{
		cout<<"IMPOSSIBLE";
	}
	else
	{
		cout<<(a+b)/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int N;
	cin >> N;
	vector<string>s(N);
	for (auto &i : s)cin >> i;
	for (int i = 1; i <= 5; i++) {
		set<string>st;
		string t(i, 'a');
		while (t[0] <= 'z') {
			st.insert(t);
			t.back()++;
			int cnt = i - 1;
			while (cnt&&t[cnt] > 'z') {
				t[cnt--] = 'a';
				t[cnt]++;
			}
		}
		for (auto j : s) {
			for (int k = 0; k + i <= j.size(); k++) {
				string u;
				for (int l = 0; l < i; l++) {
					u.push_back(j[k + l]);
				}
				st.erase(u);
			}
		}
		if (!st.empty()) {
			cout << *st.begin() << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 50620
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

ll modpow(ll a, ll b){
  if(b == 0) return 1;
  if(b & 1){
    return a * modpow(a, b - 1) % MOD;
  }else{
    ll half = modpow(a, b / 2);
    return half * half % MOD;
  }
}

ll modfact(ll n){
  ll res = 1;
  rep(i, n) res = res * (i + 1) % MOD;
  return res;
}

ll modcomb(ll n, ll r){
  ll res = 1;
  r = min(r, n - r);
  rep(i, r) res = res * (n - i) % MOD;
  return res * modpow(modfact(r), MOD - 2) % MOD;
}

ll modh(ll n, ll r){
  return modcomb(n + r - 1, r - 1);
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> v;
  ll ans = 1;
  rep(n, 2, 100000){
    if(M == 1) break;
    int num = 0;
    while(M % n == 0){
      M /= n;
      num++;
    }
    if(num){
      ans *= modh(num, N);
      ans %= MOD;
    }
  }
  if(M != 1){
    ans *= N;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import permutations

numbers = list(map(int, list(input())))

def solve():
    '''bit全探索で解く'''
    candidates = []
    for i in range(2**3):
        
        candidates.append(bin(i)[2:].zfill(3))
    
    for candidate in candidates:
        s = numbers[0]
        # print('start', list(candidate), s)
        for i, c in enumerate(list(candidate)):
            if c == '1':
                s += numbers[i+1]
            else:
                s -= numbers[i+1]
            # print(i, c, s)
        if s == 7:
            candidate = ''.join(candidate)
            candidate = candidate.replace('1', '+')
            candidate = candidate.replace('0', '-')
            for i in range(3):
                print(numbers[i], end='')
                print(candidate[i], end='')
                
            print(numbers[-1], end='')
            print('=7') 
            return

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9] * n
dp[0] = 0

for i in range(1, n):
    j = max(0, i - k)
    hi = h[i]
    dp[i] = min(dpj + abs(hi - hj) for dpj, hj in zip(dp[j:i], h[j:i]))

print(dp[-1])

Measured memory_bytes: 13980
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
    auto N = readln.split[0].to!ulong;
    auto A = readln.split.to!(ulong[]);
    N = A.length;
    auto grps = sort(A.dup).group;
    size_t[ulong] nums;
    
    //grps.array.writeln;
    
    foreach (tup; grps) {
        nums[tup[0]] = tup[1];
    }
    //nums.writeln; 
    
    ulong all_num = grps.map!(a => a[1] * (a[1]-1)).sum / 2;
    ulong all_num_true = nums.values.dup.map!(a => a*(a-1)).sum / 2;
    
    int[] re; re.length = N;
    if (
        equal( sort(grps.map!(a => a[1]).array), sort(nums.values) ) &&
        !equal( sort(grps.map!(a => a[1] * (a[1]-1)).array), sort(nums.values.map!(a => a * (a-1)).array) )
    ) {
        if (all_num_true > all_num) re[N+1] = 1;  // RE
        if (all_num_true < all_num) writeln("aaa");   // WA
    }
    
    foreach (k; 0 .. N) {
        writeln( all_num_true - (nums[A[k]] - 1) );
    }
}



Measured memory_bytes: 26768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  string s;
  svector A(n),B(m);
  rep(i,n) cin>>A[i];rep(i,m) cin>>B[i];
  bool isok=false,tmp;
  for(ll a=0;a<n;++a) {
    for(ll apos=0;apos+m<=n;apos++) {
      if(B[0]==A[a].substr(apos,m)) {
        tmp=true;
        for(ll bpos=1;bpos<m;++bpos) {
          if(a+bpos<n&&B[bpos]==A[a+bpos].substr(apos,m)) continue;
          tmp=false;
        }
        isok=tmp;
      }
      if(isok) break;
    }
    if(isok) break;
  }
  print(isok?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> a(100010);
  for(int i=0;i<n;i++){
    int p;
    cin >> p;
    a[p]++;
    a[p+1]++;
    a[p+2]++;
  }
  
  int ans=0;
  
  for(int i=0;i<100010;i++){
    ans=max(ans,a[i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3728
#include <stdio.h>
int main(void){
  int a,b,dif,i,x;
  int hb=0;

  scanf("%d %d",&a,&b);
  dif=b-a;

  for(i=1;i<=dif;i++)
    hb+=i;

  x=hb-b;

  printf("%d",x);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    string a;
    cin >> a;
    if(a[2] == 0){
      cout << a << endl;
    }else{
      for(int i = 2 ; i >=0 ; i--){
          cout << a[i];
      }
      cout << endl;
    }
}

Measured memory_bytes: 256
// use std::cmp::max;
use std::cmp::min;
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn read_str_as_char_vec() -> Vec<char> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().chars().collect()
}

fn read_str_as_T<T>() -> T
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().unwrap()
}

fn dfs(sum_money: usize, x: usize, in_vecs: &Vec<Vec<usize>>, best: i64, mut temp_sums: &mut Vec<usize>, index: usize, use_i: usize) -> i64 {
    if index == in_vecs.len() {
        for &temp_sum in temp_sums.iter() {
            if temp_sum < x {
                return 1_000_000_000_000;
            }
        }
        return sum_money as i64;
    }
    if use_i == 0 {
        let best = min(best, dfs(sum_money, x, &in_vecs, best, &mut temp_sums, index+1, 0));
        return min(best, dfs(sum_money, x, &in_vecs, best, &mut temp_sums, index+1, 1));
    } else {
        let temp_sum_base = &in_vecs[index];
        for i in 1..temp_sum_base.len() {
             temp_sums[i-1] += temp_sum_base[i];
        }

        let best = min(best, dfs(sum_money+temp_sum_base[0], x, &in_vecs, best, &mut temp_sums, index+1, 0));
        let best = min(best, dfs(sum_money+temp_sum_base[0], x, &in_vecs, best, &mut temp_sums, index+1, 1));

        for i in 1..temp_sum_base.len() {
             temp_sums[i-1] -= temp_sum_base[i];
        }
        return best;
    }
}

fn main() {
    let in_vec: Vec<usize> = read_line();
    let n = in_vec[0];
    let m = in_vec[1];
    let x = in_vec[2];

    let mut in_vecs: Vec<Vec<usize>> = Vec::new();
    for _i in 0..n {
        in_vecs.push(read_line());
    }

    let mut temp_sums: Vec<usize> = vec![0; m];
    let res = dfs(0, x, &in_vecs, 1_000_000_000_000, &mut temp_sums, 0, 0);
    let res = min(res, dfs(0, x, &in_vecs, 1_000_000_000_000, &mut temp_sums, 0, 1));
    
    if res == 1_000_000_000_000 {
        println!("{}", -1);
        return;
    }
    println!("{}", res);
}


Measured memory_bytes: 2112
import java.util.*


fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    var A: Long
    A = sc.nextLong()
    var B: Long
    B = sc.nextLong()
    solve(A, B)
}

fun solve(A: Long, B: Long) {
    var c = 1L
    var res = 0

    while (c < B) {
        c += A - 1
        res++
    }

    println(res)
}



Measured memory_bytes: 29612
N = int(input())
ans = [0]*(N+1)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            K = x**2+y**2+z**2+x*y+y*z+z*x
            if 1 <= K <= N:
                ans[K] += 1 
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 69364
use std::collections::HashSet;
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<u32> = Vec::new();
    let mut button: HashSet<u32> = HashSet::new();
    let mut idx = 0;

    for _ in 0..n {
        a.push(parse_line().unwrap());
    }
    button.insert(1);
    println!(
        "{}",
        loop {
            if a[idx] == 2 {
                break button.len() as isize;
            } else {
                if !button.insert(a[idx]) {
                    break -1;
                }
                idx = (a[idx] - 1) as usize;
            }
        }
    );
}


Measured memory_bytes: 3488
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define eps 1e-12
#define LL long long 
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
const int mod=1e9+7;
int cnt[Maxn];
int main()
{
	//input;output;
	int n,arr[Maxn],ans;
	while(~scanf("%d",&n))
	{
		ans=0;
		memset(cnt,0,sizeof(cnt));
		for(int i=0;i<n;i++)
			scanf("%d",arr+i),cnt[arr[i]]++;
		for(int i=0;i<Maxn;i++)
			if(i==0)
				ans=max(ans,cnt[0]+cnt[1]);
			else
				ans=max(ans,cnt[i-1]+cnt[i]+cnt[i+1]);
		printf("%d\n",ans);
	}
	return 0;
}

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

int i;

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

    int count = 0;

    for (i = 0; i < n; i++)
    {
        while (i + 1 < n && a[i] == a[i + 1])
        {
            i++;
        }
        if (i + 1 < n && a[i] < a[i + 1])
        {
            while (a[i] <= a[i + 1])
            {
                i++;
            }
        }
        else if (i + 1 < n && a[i] > a[i + 1])
        {
            while (a[i] >= a[i + 1])
            {
                i++;
            }
        }
        count++;
    }

    cout << count;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = (x + 1) % 2;
		System.out.println(ans);
	}

}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &m) { for (auto &e : m) os << e << endl; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll n, k; cin >> n >> k;
  vector<VV> a(2, VV(k, V(k)));

  rep(i, n) {
    int x, y; cin >> x >> y;
    char c; cin >> c;
    x %= 2*k;
    y %= 2*k;
    int z = ((c == 'B') ? 0 : 1);

    if (x >= k && y >= k) {
      x -= k;
      y -= k;
    }
    else if (x >= k) {
      x -= k;
      z ^= 1;
    }
    else if (y >= k) {
      y -= k;
      z ^= 1;
    }
    ++a[z][x][y];
  }


  vector<VV> s0(2, VV(k+1, V(k+1)));
  vector<VV> s1(2, VV(k+1, V(k+1)));
  rep(z, 2) rep(i, k) rep(j, k) {
    s0[z][i+1][j+1] = s0[z][i+1][j] + s0[z][i][j+1] - s0[z][i][j] + a[z][i][j];
  }
  rep(z, 2) drep(i, k) drep(j, k) {
    s1[z][i][j] = s1[z][i+1][j] + s1[z][i][j+1] - s1[z][i+1][j+1] + a[z][i][j];
  }

  int all0 = s1[0][0][0];
  int all1 = s1[1][0][0];

  ll ans = 0;
  rep(i, k+1) rep(j, k+1) {
    ll x = s0[0][i][j] + s1[0][i][j] + all1 - s0[1][i][j] - s1[1][i][j];
    ll y = s0[1][i][j] + s1[1][i][j] + all0 - s0[0][i][j] - s1[0][i][j];
    chmax(ans, x);
    chmax(ans, y);
  } 
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    //入力
    string S;
    cin>>S;
    
    //計算
    long count=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='o') count++;
    }
    
    //出力
    if(count+(15-S.size())>=8) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

using i64 = int64_t;

int main(){
    i64 a, b, k;
    cin >> a >> b >> k;
    i64 c = k - a;
    a = max((i64)0, a-k);
    if(c > 0)b = max((i64)0, b-c);
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define all( x ) x.begin() , x.end()
#define pb push_back
#define mp make_pair

const int maxn = 510 ;
const int INF = 1e18 ;

int n , p[ maxn*maxn ] , dis[ maxn*maxn ] , rr , ans = 0 ;
vector< int > g[ maxn*maxn ] ;
bool mark[ maxn*maxn ] ;

int ver( int i , int j )
{
   if( i < 1 || i > n || j < 1 || j > n)
     return rr ;
   return ((i-1)*n) + j ;
}

void bfs( int root )
{
  deque< int > qu ;

  qu.pb( root ) ;

  while( qu.size()){

    int v = qu.front();
    qu.pop_front();

    for(auto uu : g[ v ]){
       int u = uu , w = mark[ v ] ;

       if( (dis[ v ] + w) < dis[ u ] ){
         dis[ u ] = dis[ v ]+w ;

         if( w == 0 )
          qu.push_front( u ) ;
         else
          qu.push_back( u ) ;

       }
    }

  }

}

signed main()
{
 ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

 cin >> n ;
 for(int i = 1 ; i <= n*n ; i ++){
   cin >> p[ i ] ;
   dis[ i ] = INF ;
   mark[ i ] = true ;
 }

 rr = (n*n)+1 ;

 dis[ rr ] = 0 ;

 for(int i = 1 ;i <= n ; i ++){
   for(int j = 1 ; j <= n ; j ++){
     int v = ((i-1)*n) + j ;
     int v1 = ver( i-1 , j ) , v2 = ver( i+1 , j ) , v3 = ver( i , j+1 ) , v4 = ver( i , j-1 ) ;
     g[ v ].pb( v1 ) ;
     g[ v1 ].pb( v ) ;
     g[ v ].pb( v2 ) ;
     g[ v2 ].pb( v ) ;
     g[ v ].pb( v3 );
     g[ v3 ].pb( v ) ;
     g[ v ].pb( v4 ) ;
     g[ v4 ].pb( v ) ;
   }
 }

 bfs( rr );

 for(int i = 1 ;i <= n*n ; i ++){
   ans += dis[ p[ i ] ] ;
   mark[ p[ i ] ] = false ;
   bfs( p[ i ] ) ;
 }

 cout << ans ;

    return 0;
}


Measured memory_bytes: 34440
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pa pair<int,int>
#define pii pair<ll,ll>
#define st first
#define nd second
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

int main()
{
  BOOST;
  int h,a;
  cin>>h>>a;
  if (h%a==0)cout<<h/a;
  else cout<<h/a+1;
  return 0;
}


Measured memory_bytes: 892
let n = Scanf.scanf " %d" (+) 0
let a_ss = Array.init 2 @@ fun _ -> Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    let sum = ref 0 in
    for j = 0 to i do sum := !sum + a_ss.(0).(j) done;
    for j = i to n - 1 do sum := !sum + a_ss.(1).(j) done;
    ans := max !ans !sum done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pii pair< ll,ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define mxn 100010
#define sqr 700
#define mx 600003
ll arr[mx],dp[mx][2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin>>n;
  string s;
  cin>>s;
  ll i;
  for(i=0;i<n;i++)
  {
    dp[i+1][0]=dp[i][0];
    dp[i+1][1]=dp[i][1];
    if(s[i]=='E')  dp[i+1][0]++;
    else dp[i+1][1]++;
  }
  ll ans=n+2;
  for(i=1;i<=n;i++)
  {
    ans = min(ans,dp[i-1][1]+dp[n][0]-dp[i][0]);
  }
  cout<<ans;
}

Measured memory_bytes: 6804
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    return a % b == 0 ? b : gcd(b , a % b);
}
int main()
{
    int n , m;
    scanf("%d%d",&n,&m);
    string s , t;cin>>s>>t;
    int g = gcd(n , m);
    int N = n/g , M = m/g;
    int pn = N , pm = M;
    N = M = 0;
    while(N < n && M < m){
        if(s[N] != t[M]){
            //printf("%d %d\n",N,M);
            puts("-1");return 0;
        }
        N += pn;M += pm;
    }
    printf("%lld\n",1LL*n*m/g);
    return 0;
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            out.println((1000 - (N % 1000)) % 1000);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32668
#include<iostream>
#include<vector>
#include<queue>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int x,a,b;
  cin >>x >>a>>b;
  bool ist=false;
  
  
  
  if ( abs(x-a) < abs(x-b)   ){
    cout << "A";
  }else{
    cout << "B";
  }
  

    return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int kai = 0;
		
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		for(int i=1; i<=x/2 || i<=y/2; i++){
			if(x%i==0 && y%i==0){
				kai = i;
			}
		}
		if(x==y){
			kai = x;
		}
		
		System.out.println(kai);
	}
}


Measured memory_bytes: 26504
while True:
    n =int(input())
    if n==0:
        break
    A=[0]*32
    A[0]=0
    A[1]=1
    A[2]=2
    A[3]=4
    for i in range(4,31):
        A[i]=A[i-1]+A[i-2]+A[i-3]
    a=A[n]//3650+1
    print(a)



Measured memory_bytes: 5596
dp = [[0, 0, 0], [0, 0, 0]]
n = int(input())
for i in range(n):
    abc = list(map(int, input().split()))
    for j in range(3):
        dp[i % 2][j] = 0
        for k in range(3):
            if j != k:
                dp[i % 2][j] = max(dp[i % 2][j], dp[1 - i % 2][k])
        dp[i % 2][j] += abc[j]
print(max(dp[1 - n % 2]))

Measured memory_bytes: 46808
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    
    int ans = 0;
    
    ans += n / 500 * 1000;
    n = n % 500;
    ans += n / 5 * 5;
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<list>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<bitset>
#include<stack>
#include<string>
#include<complex>
using namespace std;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
// char buf[1<<21],*p1=buf,*p2=buf;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define ull unsigned ll
#define rg register
#define bug puts("bug");
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;
const int mod = 1e9+7;
const double eps = 1e-6;
const double pi=acos(-1);
int di[8][2]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
inline ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int cnt[maxn];
char s[maxn*2];
int main()
{
	scanf("%s",s+1);
	ll ans=0;
	int now=0;
	int m=1;
	for(int i=strlen(s+1);i;i--)
	{
		now=(now+(s[i]-'0')*m)%2019;
		cnt[now]++;
		m=m*10%2019;
	}
	for(int i=0;i<=2018;i++)
	{
		ans+=1ll*cnt[i]*(cnt[i]-1)/2;
	}
	cout<<ans+cnt[0];
}


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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int A, B, M; cin >> A >> B >> M;
	vector<int> a(A), b(B);
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}

	int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());

	while (M--) {
		int x, y, c; cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split(" ")))
q = int(input())
b = []
c = []

for _ in range(q):
	bi, ci = list(map(int, input().split(" ")))
	b.append(bi)
	c.append(ci)

dic = {}
for aa in a:
	dic[aa] = dic.get(aa, 0) + 1

s = sum(a)
for i in range(q):
	if b[i] not in dic:
		print (str(s))
		continue
	s += (c[i]-b[i]) * dic[b[i]]
	dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]
	del dic[b[i]]
	print (str(s))

Measured memory_bytes: 27032
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

int32_t main()
{
	string s;
	cin >> s;
	if (SIZ(s) % 2 != 0)
	{
		printf("No\n");
		return 0;
	}
	for (int i = 0; i < SIZ(s); i += 2)
	{
		if (s[i] != 'h' || s[i + 1] != 'i')
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}














Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	long long arr[200001];
	int n;
	long long k;

	scanf("%d %lld", &n, &k);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &arr[i]);
	}

	long long lb = 0, ub = 1000000000;

	for (long long next = (lb + ub) / 2; ub - lb > 1; next = (lb + ub) / 2)
	{
		long long cnt = 0;

		for (int i = 0; i < n; i++)
		{
			cnt += (arr[i] - 1) / next;
		}

		if (cnt > k)
		{
			lb = next;
		}

		else
		{
			ub = next;
		}
	}

	printf("%lld\n", ub);

	return 0;
}

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

int main() {
  string s;cin>>s;
  int n=s.size();
  rep(i,n){
    s.pop_back();
    int t=s.size();
    if(s.substr(0,t/2)==s.substr(t/2)){
      cout<<t<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
import std.stdio;
import std.range;

void main() {
    int N, Q;
    readf("%d %d\n", &N, &Q);

    int[] uf = new int[](N);
    foreach (int i, ref e; uf) {
        e = i;
    }

    foreach (q; iota(0, Q, 1)) {
        int p, a, b;
        readf("%d %d %d\n", &p, &a, &b);

        if (p == 0) {
            unite(a, b, uf);
        } else {
            if (find(a, b, uf))
                writeln(1);
            else
                writeln(0);
        }
    }
}

bool find(int a, int b, int[] uf) {
    return (root(a, uf) == root(b, uf));
}

void unite(int a, int b, ref int[] uf) {
    int x = root(a, uf);
    int y = root(b, uf);

    if (x != y)
        uf[x] = y;
}

int root(int x, int[] uf) {
    if (uf[x] == x)
        return x;
    else
        return uf[x] = root(uf[x], uf);
}

Measured memory_bytes: 1680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;
long long int X;
int main(void) {

	cin >> X;

	long long int ans = 0;

	long long int num = X / 500;
	X -= 500 * num;
	ans += num * 1000;

	num = X / 5;

	ans += num * 5;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  if((A-B)%2==0)cout<<abs(A-B)/2<<endl;
  else cout<<min((A+B-1)/2,(N-A+N-B+1)/2)<<endl;
}

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

using namespace std;
long long l[51];
long long p[51];


long long calc(long long d, long long x){
    if(d == 0) return 1;
    if(x <=  1) return 0;
    else if(x <= l[d - 1] + 1) return calc(d - 1, x - 1);
    else if(x == l[d - 1] + 2) return p[d - 1] + 1;
    else if(x <= 2 * l[d - 1] + 2) return p[d - 1] + 1 + calc(d - 1, x - (l[d - 1] + 2));
    else return p[d];
}

int main(){
    long long n, x, ans = 0;
    cin >> n >> x;
    l[0] = p[0] = 1;
    for(int i = 1; i <=50; i++){
        l[i] = 2 * l[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }
    ans = calc(n, x);
    cout << ans << endl;
    return 0;
}


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

const int N = 1e5;

char s[N+5];

int main(){
	scanf("%s",s);
	int pan = strlen(s);
	for(int i=0;i<pan;i+=2){
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}

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


int main() {
    string s;

    cin >> s;

    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    return 0;
}

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

int main() {
    int N, X, temp;
    std::cin >> N >> X;
    
    std::vector<int> m;
    for (auto i=0; i<N; ++i) {
        std::cin >> temp;
        m.push_back(temp);
    }
    std::sort(m.begin(), m.end());
    
    int ans = 0;
    
    for (auto itr=m.begin(); itr!=m.end(); itr++) {
        X -= *itr;
        ans++;
    }
    
    ans += X / m[0];
    
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    int s=max(a,c);
    int f=min(b,d);
    int ans=f-s;
    if(ans<0)ans=0;
    cout <<  ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char s[100],t[100],ans[3001][100];int lens,lent,tot=0;
void ffind(int k){
	int i,kk=k;
	for(i=0;i<lent;i++,kk++)
		if(s[kk]!=t[i] && s[kk]!='?')break;
	if(i==lent){
		for(int j=0;j<lens;j++)ans[tot][j]=s[j];
		for(int j=k;j<lent+k;j++)ans[tot][j]=t[j-k];
		for(int j=0;j<lens;j++)
			if(ans[tot][j]=='?')ans[tot][j]='a';
		tot++;
	}
}
int getAns(){
	if(tot==0)return -1;
	int minn=0;
	for(int i=1;i<=tot-1;i++)
		if(strcmp(ans[minn],ans[i])!=-1)minn=i;
	return minn;
}
int main(){
	cin>>s>>t;
	lens=strlen(s),lent=strlen(t);
	for(int i=0;i<=lens-lent;i++)
		if(s[i]==t[0] || s[i]=='?')ffind(i);
	int tmp=getAns();
	if(tmp==-1)cout<<"UNRESTORABLE";
	else for(int i=0;i<lens;i++)cout<<ans[tmp][i];
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  map<string, int> m;

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ans += m[s];
    m[s]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11328
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> VU.Vector (Int, Int, Int) -> Int
solve n abcs =
  uread (toIndex (n - 1) 'a') dp
    `max` uread (toIndex (n - 1) 'b') dp
    `max` uread (toIndex (n - 1) 'c') dp
 where
  toIndex i 'a' = i
  toIndex i 'b' = i + n
  toIndex i 'c' = i + 2 * n

  dp = VU.foldl'
    ( \(!dp) (!i, (!ai, !bi, !ci)) -> if i == 0
      then uwrite (toIndex i 'a') ai $ uwrite (toIndex i 'b') bi $ uwrite
        (toIndex i 'c')
        ci
        dp
      else
        let ai' = uread (toIndex (i - 1) 'a') dp
            bi' = uread (toIndex (i - 1) 'b') dp
            ci' = uread (toIndex (i - 1) 'c') dp
        in  uwrite (toIndex i 'a') (ai + max bi' ci')
            $ uwrite (toIndex i 'b') (bi + max ai' ci')
            $ uwrite (toIndex i 'c') (ci + max ai' bi') dp
    )
    (unew (n * 3))
    (VU.indexed abcs)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  n    <- (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  abcs <-
    VU.replicateM n
    $   (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  print $ solve n abcs


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  vector<int> l;
  cin >> n;
  for(int i = 0;i < 2 * n; i++) {
    int x;
    cin >> x;
    l.push_back(x);
  }
  sort(l.begin(), l.end());
  int ans = 0;
  for(int i = 0;i < l.size(); i += 2) {
    ans += l[i];
  }
  cout << ans << endl;
}


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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//
int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a, b, c;
    cin >> a >> b >> c;
    int ans = min( INF32, abs(b-a) + abs(c-b));
    ans = min(ans, abs(c-a) + abs(b-c));

    ans = min(ans, abs(a-b) + abs(c-a));
    ans = min(ans, abs(c-b) + abs(a-c));

    ans = min(ans, abs(b-c) + abs(a-b));
    ans = min(ans, abs(a-c) + abs(b-a));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

var mod int = int(1e9 + 7)
var chars []string = []string{
  "A",
  "C",
  "G",
  "T",
}

var n int
var memo [101]map[string]int

func ok(str string) bool {
  org := []rune(str)
  s := make([]rune, len(org))
  for i:=0; i<4; i++ {
    copy(s, org)

    if i < 3 {
      s[i], s[i+1] = s[i+1], s[i]
    }

    if strings.Contains(string(s), "AGC") {
      return false
    }
  }
  return true
}

func rec(i int, last3 string) int {
	v, exists := memo[i][last3]
	if exists {
		return v
	}

	if i == n {
		return 1
	}
	
	var ret int
	for _, c := range chars {
		if ok(last3 + c) {
			ret = (ret + rec(i+1, string(last3[1:] + c))) % mod
		}
	}
	
	memo[i][last3] = ret
	return ret
}

func main() {
	fmt.Scan(&n)
	for i:=0; i<101; i++ {
		memo[i] = map[string]int{}
	}

	fmt.Println(rec(0, "TTT"))

}


Measured memory_bytes: 2688