akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long  ll;


int f[100005];
int rk[1000005];
int find(int x){
    if(f[x]!=x) f[x]=find(f[x]);
    return f[x];
}



int main(int argc, const char * argv[]) {
    
    
    for(int i=1;i<=100000;i++) {f[i]=i;};
    
    int n,m;cin>>n>>m;
    int cnt=0;
    while (m--) {
        int u,v;cin>>u>>v;
        u=find(u);
        v=find(v);
        if(u==v) continue;
        f[u]=v;
        cnt++;
    }
    cout<<n-1-cnt<<endl;
    
    
    


    
    
   
    
    
    
     
    return 0;
}




Measured memory_bytes: 4028
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MAX = 80 * 80;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int> > v(h, vector<int>(w));
    for(int i=0; i<2; ++i){
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                int a;
                cin >> a;
                v[y][x] = abs(v[y][x] - a);
            }
        }
    }

    vector<vector<vector<bool> > > dp(h, vector<vector<bool> >(w, vector<bool>(MAX+1, false)));
    dp[0][0][v[0][0]] = true;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            for(int i=0; i<2; ++i){
                int y2 = y + i;
                int x2 = x + (i ^ 1);
                if(y2 >= h || x2 >= w)
                    continue;
                for(int k=0; k<=MAX; ++k){
                    if(dp[y][x][k])
                        dp[y2][x2][abs(k-v[y2][x2])] = true;
                }
                for(int k=0; k<=MAX-v[y2][x2]; ++k){
                    if(dp[y][x][k])
                        dp[y2][x2][k+v[y2][x2]] = true;
                }
            }
        }
    }

    int ans = 0;
    while(!dp[h-1][w-1][ans])
        ++ ans;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> cnt;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    if (A.size() == 1) {
        if (A[0] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if (A.size() == 2) {
        if (N % 3 == 0 && cnt[0] == N / 3) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if (A.size() == 3) {
        if (N % 3 != 0) {
            cout << "No" << endl;
            return 0;
        }
        for (int i = 0; i < A.size(); i++) {
            if (cnt[A[i]] != N / 3) {
                cout << "No" << endl;
                return 0;
            }
        }
        if ((A[0] ^ A[1]) == A[2]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4224
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<unordered_map>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl
#define wa()  cout<<"No"<<endl
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
#define SZ(x) x.size()
#define epp empty()
#define all(x) x.begin(),x.end()
typedef vector<int> VE;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=5e6+5;
char s[maxm];
int d[maxm][5];
signed main(){
    int n=re;
    scanf("%s",s+1);
    ff(i,n){
        if(s[i]=='R')s[i]=1;
        else if(s[i]=='G')s[i]=2;
        else s[i]=3;
    }
    for(int i=n;i>=1;i--){
        for(int j=1;j<=3;j++)d[i][j]=d[i+1][j];
        d[i][(int)s[i]]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++){//枚举i
        for(int j=i+1;j<=n;j++){//枚举j
            if(s[i]!=s[j]){
                int t=6-s[i]-s[j];
                ans+=d[j+1][t];
                int tt=j-i;
                tt=j+tt;
                if(s[tt]==t)ans--;
            }
        }
    }
    pr(ans);
    return 0;
}


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

int main () {
	
	int n=0, x=0; 
	int res = 0;

	cin >> n;

	cin >> x;

	res = x;

	for (int i=1; i<n; i++) {
		cin >> x;
		res = __gcd(res, x);
	}

	cout << res << endl; 

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
    int h, w;
    char a[102][102];

    cin >> h >> w;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> a[i][j];
        }
        a[i][0]='#';
        a[i][w+1]='#';
    }
    

    for (int i = 0; i <= h + 1; i++)
    {
        for (int j = 0; j <= w + 1; j++)
        {
            if (i == 0 || i == h + 1)
            {
                cout << "#";
            }
            else
            {

                cout << a[i][j];
            }
        }
        cout << endl;
    }

    return 0;
};

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 998244353;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

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

int main(void) {

  ll k, s;
  cin >> k;

  ll ans = 0;
  for (ll i = 1; i <= k; i++) {
    for (ll j = 1; j <= k; j++) {
      for (ll t = 1; t <= k; t++) {
	
	ans += (gcd(i, gcd(j, t)));
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(){
int testcase;
int ac=0,wa = 0,tle = 0,re =0;
char input[50];
scanf("%d",&testcase);
for(int i = 0;i<testcase;i++){
	scanf("%s",input);
	if(input[0]=='A'){
		ac++;
	}
	else if(input[0]=='W'){
		wa++;
	}	
	else if(input[0]=='T'){
		tle++;
	}
	else if(input[0]=='R'){
		re++;
	}
}
	printf("AC x %d\n",ac);
	printf("WA x %d\n",wa);
	printf("TLE x %d\n",tle);
	printf("RE x %d\n",re);

	return 0;
}

Measured memory_bytes: 1732
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD  = 1000000000 + 7;
constexpr int INF  = 2000000000;
constexpr LL  LINF = 2000000000000000;
int main() {
	int n, p;
	cin >> n >> p;
	int count = 0;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1)count++;
	}
	LL ans;
	if (count)ans = (1LL << (n - 1));
	else if (p && !count)ans = 0;
	else ans = (1LL << n);
	cout << ans << endl;
}

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

int main() {
    string S;
    cin>>S;
    for (int i(0);i<=2;i++){
      if (S[i]==S[i+1]){
        cout<<"Bad"<<endl;
        return 0;
      }
    }
    cout << "Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
m = int(input())
a = list(map(int, input().split()))
output = [0] * 2019

for i in x:
    output[i - 1] = 1


for k in range(m):
    count = 0
    for l in range(2019):
        if output[l] == 1:
            count += 1


        if count == a[k]:
            if l == 2018:
                break

            if output[l + 1] == 0:
                output[l], output[l + 1] = 0, 1

for i in range(2019):
    if output[i] == 1:
        print(i + 1)



Measured memory_bytes: 5628
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = sc.nextLong();

		List<Long> timeList = Arrays.asList(A, B, C, D, E);
		long minTime = timeList.stream()
                .min((a, b) -> a.compareTo(b)).get();
		int minIndex = timeList.indexOf(minTime);


		long time = N/minTime;
		if(N%minTime != 0){
			time++;
		}

		time += 5- (minIndex+1) + minIndex;

		System.out.println(time);


	}


}


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

int main(){
    int N, K;
    cin >> N >> K;

    vector<long> H(N);
    rep(i, N) cin >> H[i];

    sort(H.begin(), H.end(), greater<long>());

    long long sum = 0;
    for (int i = K; i < N; i++){
        sum += H[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1920
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    s=input()
    ans=[s[0],str(len(s)-2),s[-1]]
    print(''.join(map(str, ans)))

main()


Measured memory_bytes: 38384
### main

while true
  n = gets.strip.to_i
  break if n == 0

  chlds = []
  n.times.each do
    d, v = gets.strip.split(' ').map{|s| s.to_i}
    chlds << Rational(v, d)
  end
  #p chlds

  time = chlds.inject(1){|t, c| t.lcm(c.denominator)}
  #p time

  rounds = chlds.map{|c| (c * time).numerator}
  #p rounds

  rgcd = rounds.inject{|rg, r| rg.gcd(r)}
  #p rgcd

  for r in rounds
    puts r / rgcd
  end
end

Measured memory_bytes: 6140
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Making Triangle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int ls[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", ls + i);

  int c = 0;
  for (int i = 0; i < n; i++) {
    int li = ls[i];
    for (int j = i + 1; j < n; j++) {
      int lj = ls[j];
      if (li != lj)
	for (int k = j + 1; k < n; k++) {
	  int lk = ls[k];
	  if (li != lk && lj != lk &&
	      li + lj > lk && lj + lk > li && lk + li > lj)
	    c++;
	}
    }
  }

  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}else if(n == 1){
				for(int i = 0;i < 10;i++){
					if(i == scan.nextInt()){
						System.out.println("*");
					}else{
						System.out.println("-");
					}
				}
				continue;
			}
			int[] ice = new int[10];
			for(int i = 0;i < n;i++){
				ice[scan.nextInt()]++;
			}
			for(int i = 0;i < 10;i++){
				if(ice[i] == 0){
					System.out.print("-");
				}else{
					for(int j = 0;j < ice[i];j++){
						System.out.print("*");
					}
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 54128
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	deque<int> b;
	ff(i, 0, n) {
		cin >> a.at(i);
	}
	ff(i, 0, n) {
		if (n % 2 != i % 2) {
			b.push_front(a.at(i));
		}
		else {
			b.push_back(a.at(i));
		}
	}
	cout << b.at(0);
	ff(i, 1, n) {
		cout << " " << b.at(i);
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 0 && A.at(i) % 3 != 0 && A.at(i) % 5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;

  return 0;
}


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

using namespace std;
int main(void){
    string s;cin>>s;
    int flag=0;
    
    for(int i = 0;i<s.size();i++){
        for(int j=0;j<s.size();j++){
            if(i!=j){
                if(s[i] == s[j]) flag = 1;
            }
        }   
    }
    if(flag) cout<<"no";
    else cout<<"yes";
    
    
}


Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.09.07 15:58:48
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int  a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b) )<<endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main(void)
{
    int N, K;
    scanf("%d %d", &N, &K);

    vector<int> H(N + 10);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &H[i]);
    }

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

    printf("%d\n", ans);
}

Measured memory_bytes: 640
while true
m,f,r=gets.split(" ").map(&:to_i)
break if m==-1 && f==-1 && r==-1
#if (m+f+r)<30
grade="F"
if m == -1 || f == -1
    grade="F"

elsif m + f >=80 
    grade= "A"
elsif m + f >=65
    grade= "B"
elsif m + f>=50
    grade="C"
elsif m + f>=30
    if r >= 50
        grade= "C"
    else
        grade= "D"
    end
end

puts grade


end








Measured memory_bytes: 6872
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
total = sum(a) // 2
x = [a[i] for i in range(1, n-1, 2)]
ans[0] = total-sum(x)
for i in range(1, n):
    ans[i] = a[i-1] - ans[i-1]
ans = [2 * x for x in ans]
print(*ans)


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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 12;
int INF=10000000;
int main()
{
  int n,m,x,t,tt,tm,i,j,rt,res=INF;
  bool f;
  int c[N_MAX],a[N_MAX][N_MAX],aa[N_MAX];
  cin >> n >> m >> x;
  for(i=0;i<n;i++){
    cin >> c[i];
    for(j=0;j<m;j++)
      cin >> a[i][j];
  }
  t=1<<n;
  for(tt=0;tt<t;tt++){
    tm=tt;
    rt=0;
    f=1;
    fill(aa,aa+m,0);
    for(i=0;i<n;i++){
      if(tm%2==1){
        rt+=c[i];
        for(j=0;j<m;j++)
          aa[j]+=a[i][j];
      }
      tm/=2;
    }
    for(j=0;j<m;j++)
      if(aa[j]<x){
        f=0;
        break;
      }
    if(f==1)
      res=min(rt,res);
  }
  if(res==INF)
    res=-1;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define ll long long
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;

int main() { _
    int n, m, z, ans = 0; cin >> n >> m >> z;
    char arr[6][6];
    set <int> row, col;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> arr[i][j];
        }
    }
    int count = 0;
    for(int i = 0; i < (1 << n); i++){
        for(int j = 0; j < n; j++){
            if((i >> j) & 1){
                row.insert(j);
            }
        }
        for(int k = 0; k < (1 << m); k++){
            for(int l = 0; l < m; l++){
                if((k >> l) & 1){
                    col.insert(l);
                }
            }
            for(int a = 0; a < n; a++){
                for(int b = 0; b < m; b++){
                    if(row.find(a) != row.end() || col.find(b) != col.end()){
                        continue;
                    }else{
                        if(arr[a][b] == '#'){
                            count++;
                        }
                    }
                }
            }
            if(count == z){
                ans++;
            }
            count = 0; col.clear();
        }
        row.clear();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define MAXN	105
#define INF	1e18
#define P	1000000007
long long fib[MAXN];
vector<pair<long long, long long> > a[MAXN];
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int main(){
	fib[0] = fib[1] = 1;
	int tot = 1;
	while (true) {
		fib[tot + 1] = fib[tot] + fib[tot - 1];
		if (fib[tot + 1] > INF) break;
		tot++;
	}
	a[1].push_back(make_pair(1, 2));
	a[1].push_back(make_pair(1, 3));
	a[1].push_back(make_pair(1, 4));
	for (int i = 1; i <= tot - 3; i++) {
		for (unsigned j = 0; j < a[i].size(); j++) {
			long long x = a[i][j].first;
			long long y = a[i][j].second;
			x += y;
			while (x <= fib[i + 3] + fib[i]){
				a[i + 1].push_back(make_pair(y, x));
				x += y;
			}
		}
	}
	int q; read(q);
	while (q--){
		long long n, m;
		read(n), read(m);
		if (n > m) swap(n, m);
		int ans = 1;
		while (fib[ans + 1] <= n && fib[ans + 2] <= m)
			ans++;
		printf("%d ", ans);
		if (ans == 1) {
			printf("%lld\n", n * m % P);
			continue;
		}
		else {
			long long num = 0;
			for (unsigned j = 0; j < a[ans - 1].size(); j++) {
				long long x = a[ans - 1][j].first;
				long long y = a[ans - 1][j].second;
				if (x <= m && y <= n) num = (num + (m - x) / y) % P;
				if (x <= n && y <= m) num = (num + (n - x) / y) % P;
			}
			printf("%lld\n", num);
		}
	}
}

Measured memory_bytes: 4096
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{   
	    Scanner sc = new Scanner(System.in);
	    String s = sc.next();
	    char[] chars = s.toCharArray();
	    for(char c : chars) {
	        if(c=='1') {
	            System.out.print(9);
	        } else {
	            System.out.print(1);
	        }
	    }
	    
	    
	}
}


Measured memory_bytes: 23892
#include <stdio.h>
#include <stdlib.h>

int main(){

  int a,b,c,r,x,y,flag;

  scanf("%d%d",&a,&b);

  if(a == b){
    printf("%d\n",a);
    return 0;
  }
  else if(a > b){
    flag = 0;
    c = b;
  }
  else{
    c = a;
    flag = 1;
  }
  
  if(flag == 0) r = a % b;
  if(flag == 1) r = b % a;

  while(1){
    x = c % r;
    if(x == 0) break;
    c = r;
    r = x;
    // printf("%d %d %d\n",x,c,r);
  }

  printf("%d\n",r);

  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
const int N_max=51;
const int M_max=N_max*(N_max-1);
vector<int> v[51];
bool isVisited[N_max];
void initialize(){
    REP(i,N_max){
        isVisited[i]=false;
    }
}
void dfs(int v_now){
    isVisited[v_now]=true;
    for(int i:v[v_now]){
        if(!isVisited[i]){
            dfs(i);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S_ori=in<string>();
    REP(i,16){
        string S;S="";
        if((1&i>>0)==1){
            S.push_back('A');
        }
        S.push_back('K');
        S.push_back('I');
        S.push_back('H');
        if((1&i>>1)==1){
            S.push_back('A');
        }
        S.push_back('B');
        if((1&i>>2)==1){
            S.push_back('A');
        }
        S.push_back('R');
        if((1&i>>3)==1){
            S.push_back('A');
        }
        if(S_ori==S){
            print("YES");
            return 0;
        }
    }
    print("NO");
    return 0;
}

Measured memory_bytes: 256
let n = stdin.ReadLine()

let rec divide i length count=
    match i  with
    | _ when i = n.Length ->
        count
    | _ when i = n.Length + 1 ->
        count-1
    |_ ->
        let single = n.Substring(i,1)
        match length with
        | 2 ->
            divide (i+1) 1 (count+1)
        | 1 ->
            match n.Substring(i-1,1)=single with
            | true ->
                divide (i+2) 2 (count+1)
            |false ->
                divide (i+1) 1 (count+1)

divide 1 1 1 |> stdout.WriteLine 


Measured memory_bytes: 18128
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int d = Integer.parseInt(sc.next());
		int t = Integer.parseInt(sc.next());
		int s = Integer.parseInt(sc.next());

		System.out.println(s * t >= d ? "Yes" : "No");

	}
}


Measured memory_bytes: 35620
#include<stdio.h>
#include<algorithm>
using namespace std;
   int main()
   {
   int a,b,c;
   int d[200005];
	while(scanf("%d",&a)!=EOF)
	   {
	   int t=0,y;	
	   for(int i=0;i<a;i++)
		   {
		   scanf("%d",&d[i]);	
			if(d[i]>=t)
				{
				t=d[i];
			   y=i;
				}
			}
		sort(d,d+a);
		for(int i=0;i<a;i++)	
		   {
		   if(i!=y)
			printf("%d\n",d[a-1]);
			else
			printf("%d\n",d[a-2]);	
			}
		  }	
	}

Measured memory_bytes: 2432
inf = float('inf')

N = int(input())
w = tuple(map(int, input().split()))

c = [0]
for ww in w:
    c.append(c[-1] + ww)
sw = sum(w)

ans = inf
for i in range(1, N):
    left = c[i]
    right = sw - c[i]
    ans = min(ans, abs(right - left))
print(ans)


Measured memory_bytes: 38256
#include <stdio.h>
#include <math.h>
#include <string.h>
 
int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }
 
    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
 
    return b;
}
 
 
 
/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする
 
  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);
 
  swap(&array[pivot], &array[j]);   //pivotを更新
 
  return j;
}
 
/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;
 
  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}
 
 
 
int main(void){
    int n, k;
    scanf("%d%d",&n, &k);
    int p[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
 
    quick_sort(p,0,n-1);
    int s;
    for(i=0; i<k; i++){
      s+=p[i];
    }
    printf("%d\n", s);
 
    return 0;
}

Measured memory_bytes: 1732
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	as := make([]int, n)
	flag := false
	for i := 0; i < n; i++ {
		as[i] = func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
		if as[i] == 2 {
			flag = true
		}
	}
	if !flag {
		fmt.Println(-1)
		return
	}
	route := map[int]bool{}
	count := 0
	index := 0
	for {
		if route[index] || count > n {
			fmt.Println(-1)
			break
		} else if index == 1 {
			fmt.Println(count)
			break
		}
		route[index] = true
		index = as[index] - 1
		count++
	}
}

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

int main(){

int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
	cin>>arr[i];
}
int x;
cin>>x;
int a[x],b[x];
for(int i=0;i<x;i++){
	
	cin>>a[i]>>b[i];
}for(int y=0;y<x;y++){
	int sum=0;
	for(int z=0;z<n;z++){
		if(z==(a[y]-1))
        sum+=b[y];
		else
		sum+=arr[z];		
	}
	cout<<sum<<"\n";
}
return 0;
} 


Measured memory_bytes: 384
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
// typedef vector<int> v;

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //




int main() {
  ll n,k,R,S,P;
  string t;
  ll ans=0;
  std::vector<char> v;

  cin >> n >> k >> R >> S >> P >> t;
  for (ll i=0; i<k; i++) {
    if (t[i] == 'r') v.pb('p');
    if (t[i] == 's') v.pb('r');
    if (t[i] == 'p') v.pb('s');
    // cout << ans << endl;
  }

  for (ll j=k; j<n; j++) {
    if (t[j] == 'r') {
      if (v[j-k] != 'p') v.pb('p');
      else v.pb('z');
    }

    if (t[j] == 's') {
      if (v[j-k] != 'r') v.pb('r');
      else v.pb('z');
    }

    if (t[j] == 'p') {
      if (v[j-k] != 's') v.pb('s');
      else v.pb('z');
    }

  }
  rep(i, n) {
    if (v[i] == 'p') ans += P;
    if (v[i] == 's') ans += S;
    if (v[i] == 'r') ans += R;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define int long long int
int w=1000000007;
 int power(int a,int b){

  if(a==0)
    return 0;
  if(b==0)
    return 1;
  if(b%2){
    int y=power(a,b-1);
    a=a%w;
    y=(y*a)%w;
    return y;}
  else{
   int y=power(a,b/2);
    y=(y*y)%w;
    return y;
}}

int modinv(int x,int p){
 return power(x,p-2);}
signed main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
int n,k;
cin>>n>>k;

int ans=0;
int sum=((n%w)*(n+1)%w)%w;
sum=(sum*modinv(2,w))%w;
for(int i=k;i<=n;i++){

   int mn=(((i-1)%w)*(i%w))%w;
   mn=(mn*modinv(2,w))%w;
   int mx=((n-i)%w)*((n-i+1))%w;
   mx=(mx*modinv(2,w))%w;
   mx=(sum-mx+w)%w;
    ans=(ans+mx-mn+w+1)%w;
}
cout<<ans+1<<endl;

}


}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	string s;
	cin >> s;
	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		int total = 0;
		int y = 0;
		
		for(int i = 0; i < n; i++){
			numbers[i] = scanner.nextInt();
			if(numbers[i] <= 3){
				total++;
			}else if(numbers[i] % 2 != 0){
				double x = Math.sqrt(numbers[i]);
				for(int j = 2; j <= x; j++){
				    y = 0;
					if(numbers[i] % j == 0){
					    y = 1;
						break;
					}
				}
				if(y == 0){
				    total++;
				}
			}
		}

		System.out.println(total);
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort (A.begin(), A.end());
  
  bool same = false;
  for (int i = 0; i < (A.size() - 1); i++) {
    if (A.at(i) == A.at(i + 1)) {
      same = true;
      break;
    }
  }
  
  if (same) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll x, y;
    cin >> x >> y;

    ll res = 0;
    if(y > x){
        if(y*x >= 0){
            res = y-x;
        }else{
            if(abs(y) > abs(x)){
                res = y-abs(x)+1;
            }else if(abs(y) < abs(x)){
                res = abs(x)-y+1;
            }else{
                res = 1;
            }
        }
    }else{
        if(abs(x) > abs(y)){
            if(x*y <= 0){
                res = abs(x)-abs(y)+1;
            }else{
                res = abs(x)-abs(y)+2;
            }
        }else if(abs(x) < abs(y)){
            if(x >= 0){
                res = abs(y)-x+1;
            }else{
                res = abs(y)-abs(x)+2;
            }
        }else{
            res = 1;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
ll dp[2003][2003];
int main(){
    int n;
    cin >> n;
    vector<P> vp;
    
    dp[0][0]=0ll;
    rp(i,n){
        int a;
        cin >> a;
        vp.push_back(make_pair(a,i+1));
    }
    sort(vp.begin(),vp.end());
    reverse(vp.begin(),vp.end());
    for(int i=1; i<n+1; i++){
        dp[i][0]=dp[i-1][0]+(ll)vp[i-1].first*(vp[i-1].second-i);
        dp[0][i]=dp[0][i-1]+(ll)vp[i-1].first*(n-i+1-vp[i-1].second);
    }
    for(int i=1; i<n; i++){
        for(int j=1; j<n-i+1; j++){
            dp[i][j]=max(dp[i-1][j]+(ll)vp[i+j-1].first*(vp[i+j-1].second-i),
                dp[i][j-1]+(ll)vp[i+j-1].first*(n-j+1-vp[i+j-1].second));
        }
    }
    ll ans=0ll;
    rp(i,n+1){
        ans=max(ans,dp[i][n-i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


double const eps = 1e-10;
double const pi = 3.1415926535;
ll const mod = 1e9+7;


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

    int n;
    string s,k;
    string res = "";
    cin >> n;
    cin >> s >> k;
    for ( int i = 0; i < n; i++ )
    {
        res += s[i];
        res += k[i];
    }
    cout << res;


    return 0;
    // 274751WM
}


Measured memory_bytes: 256
taka_f,taka_p,aoki_f,aoki_p = map(int,input().split())
taka_life_span = -(-taka_f//aoki_p)
aoki_life_span = -(-aoki_f//taka_p)
print("Yes" if taka_life_span >= aoki_life_span else "No")

Measured memory_bytes: 9132
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        if (scanInt() >= 30) {
            out.print("Yes");
        } else {
            out.print("No");
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32700
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int W = sc.nextInt();
		int H = sc.nextInt();
		
		String s = "";
		for (int i = 0; i < H+2; i++) {
			s += "#";
		}
		
		System.out.println(s);
		for (int i = 0; i < W; i++) {
			System.out.println("#" + sc.next() + "#");
		}
		System.out.println(s);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> P(n, 0);
    for(auto& p :P){
        cin >> p;
    }
    int ans = 0;
    for (int i = 0; i < n - 2; ++i)
    {
        if( (P[i] < P[i+1] and P[i+1] < P[i+2]) or
            (P[i] > P[i+1] and P[i+1] > P[i+2])){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    var(string, s);

    vector<int> a(N);
    rep(i, 0, N) {
        if (s[i] == 'R') a[i] = 0;
        if (s[i] == 'G') a[i] = 1;
        if (s[i] == 'B') a[i] = 2;
    }

    auto cnt = makeV(0, 3, N + 1);
    rep(i, 0, N) {
        cnt[0][i + 1] = cnt[0][i] + (a[i] == 0);
        cnt[1][i + 1] = cnt[1][i] + (a[i] == 1);
        cnt[2][i + 1] = cnt[2][i] + (a[i] == 2);
    }

    dump(cnt[0]);
    dump(cnt[1]);
    dump(cnt[2]);

    const auto hoge = [](int a, int b) {
        if (a > b) swap(a, b);
        if (a == 0 && b == 1) return 2;
        if (a == 0 && b == 2) return 1;
        if (a == 1 && b == 2) return 0;
        return -1;
    };

    i64 ans = 0;
    rep(i, 0, N) rep(j, i + 1, N) {
        const int len = j - i;
        const int kk = j + len;
        const int x = a[i];
        const int y = a[j];
        if (x == y) continue;
        const int z = hoge(x, y);
        ans += cnt[z][N] - cnt[z][j + 1];
        if (kk < N && a[kk] == z) ans -= 1;
    }

    print(ans);

    return 0;
}


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

int main()
{
	ll A,B;
	cin >> A >> B;
	B++;
	ll ans = 0;
	ll tempB = B / 2;
	ll tempA = A / 2;
	if ((tempB - tempA) % 2 == 1) ans += 1;
	for (int i = 2; i < 45; ++i)
	{
		tempB = B % (1ull << i);
		tempB = max(ll(0),tempB - ll(1ull << (i-1)));
		tempA = A % (1ull << i);
		tempA = max(ll(0),tempA - ll(1ull << (i-1)));
		//cout << tempA << " " << tempB << " " << i << endl;
		if ((tempB - tempA) % 2 != 0) 
		{
			ans += ll(1ull << (i-1));
			//cout << i-1 << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int a, b, c;
    cin>>a>>b>>c;
    int ans = min<int>({abs(a-b)+abs(b-c), abs(a-c)+abs(c-b), abs(b-a)+abs(a-c), abs(b-c)+abs(c-a), abs(c-a)+abs(a-b), abs(c-b)+abs(b-a) });
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
int main()
{
  int n,x,cnt=0,pre=0;
  scanf("%d%d",&n,&x);
  for(int i=0;i<n;++i)
  {
    int l;
    scanf("%d",&l);
    pre = pre+l;
    if(pre<=x) cnt++;
  }
  printf("%d\n",cnt+1);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 256
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type fixnum *obs-n* *path-n*))
(defvar *obs-n* (read))
(defvar *path-n* (read))

(declaim (type (simple-array boolean (*)) *good-obs*))
;; observatory n is good when (aref *good-obs* n)
(defvar *good-obs* (make-array (+ *obs-n* 1)
			       :initial-element t
			       :element-type 'boolean))

(declaim (type (simple-array fixnum (*)) *heights*))
(defvar *heights* (make-array (+ *obs-n* 1)
			      :initial-element -1
			      :element-type 'fixnum))
(loop for i from 1 to *obs-n* do
      (setf (aref *heights* i) (read)))

(dotimes (i *path-n*)
  (let* ((a (read))
	 (b (read)))
    (declare (type fixnum a b))
    (let ((h-a (aref *heights* a))
	  (h-b (aref *heights* b)))
      (cond ((> h-a h-b) ;; b is bad
	     (setf (aref *good-obs* b) nil))
	    ((< h-a h-b) ;; a is bad 
	     (setf (aref *good-obs* a) nil))
	    (t ;; both are bad
	     (psetf (aref *good-obs* a) nil (aref *good-obs* b) nil))))))

(princ (1- (count t *good-obs*))) ;; (aref *good-obs* 0)


Measured memory_bytes: 78844
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e2 + 5,M=1e5 + 5;
int arr[N];
int pre[N];
ll dp[N][M];
ll OO=1e12; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX;
ll l,r,mid;
ll a,b,c,d;

ll Solve(int idx,ll rem){
	
		
	if(idx == n)
		return 0;
	
	ll &ret = dp[idx][rem];
	if(~ret)
		return ret;
	
	ret = Solve(idx+1,rem);
	if(arr[idx] <= rem)
		ret = max(ret , pre[idx] + Solve(idx+1,rem-arr[idx]));

	return ret ;
}



 
 
int main(){
	
	memset(dp, -1 ,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>arr[i]>>pre[i];
	

	cout<<Solve(0,m)<<endl;
	

	


}

Measured memory_bytes: 82432
var a,b,c:array[0..20] of longint;
    re,i,n:longint;
begin
	readln(n);
	for i:=1 to n do read(a[i]);
	for i:=1 to n do read(b[i]);
	for i:=1 to n-1 do read(c[i]);
	re:=0; a[0]:= n + 1;
	for i:=1 to n do
	  begin
	    inc(re,b[a[i]]);
	    if a[i] = a[i-1] + 1 then inc(re,c[a[i-1]])
	  end; 
	write(re);
end.

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

map<char, string> tr1;
map<string, char> tr2;

int main() {
	tr1[' '] = "101";
	tr1['\''] = "000000";
	tr1[','] = "000011";
	tr1['-'] = "10010001";
	tr1['.'] = "010001";
	tr1['?'] = "000001";
	tr1['A'] = "100101";
	tr1['B'] = "10011010";
	tr1['C'] = "0101";
	tr1['D'] = "0001";
	tr1['E'] = "110";
	tr1['F'] = "01001";
	tr1['G'] = "10011011";
	tr1['H'] = "010000";
	tr1['I'] = "0111";
	tr1['J'] = "10011000";
	tr1['K'] = "0110";
	tr1['L'] = "00100";
	tr1['M'] = "10011001";
	tr1['N'] = "10011110";
	tr1['O'] = "00101";
	tr1['P'] = "111";
	tr1['Q'] = "10011111";
	tr1['R'] = "1000";
	tr1['S'] = "00110";
	tr1['T'] = "00111";
	tr1['U'] = "10011100";
	tr1['V'] = "10011101";
	tr1['W'] = "000010";
	tr1['X'] = "10010010";
	tr1['Y'] = "10010011";
	tr1['Z'] = "10010000";

	tr2["00000"] = 'A';	
	tr2["00001"] = 'B';	
	tr2["00010"] = 'C';	
	tr2["00011"] = 'D';	
	tr2["00100"] = 'E';	
	tr2["00101"] = 'F';	
	tr2["00110"] = 'G';	
	tr2["00111"] = 'H';	
	tr2["01000"] = 'I';	
	tr2["01001"] = 'J';	
	tr2["01010"] = 'K';	
	tr2["01011"] = 'L';	
	tr2["01100"] = 'M';	
	tr2["01101"] = 'N';	
	tr2["01110"] = 'O';	
	tr2["01111"] = 'P';	
	tr2["10000"] = 'Q';	
	tr2["10001"] = 'R';	
	tr2["10010"] = 'S';	
	tr2["10011"] = 'T';	
	tr2["10100"] = 'U';	
	tr2["10101"] = 'V';	
	tr2["10110"] = 'W';	
	tr2["10111"] = 'X';	
	tr2["11000"] = 'Y';	
	tr2["11001"] = 'Z';	
	tr2["11010"] = ' ';	
	tr2["11011"] = '.';	
	tr2["11100"] = ',';	
	tr2["11101"] = '-';	
	tr2["11110"] = '\'';	
	tr2["11111"] = '?';	
	
	string str;
	while (getline(cin, str)) {
		string tmp = "";
		for (int i=0; i<str.size(); i++)
			tmp += tr1[str[i]];

		int s = tmp.size() % 5;
		if (s != 0) 
			for (int i=0; i<5-s; i++)
				tmp += "0";

		for (int i=0; i<tmp.size()/5; i++)
			cout << tr2[tmp.substr(i*5, 5)];

		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0