akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree< long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void erase ( ordered_set &s, long long val )
{
    auto it = s.upper_bound(val);

    if ( it == s.begin() && val == *s.begin() )
        s.erase ( s.upper_bound(val) );
    else
        s.erase ( s.upper_bound(val) );
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


int main()
{
    su;
    map<string,int> m;
    tt
    {
      string s;
      cin>>s;
      m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<nl;
    cout<<"WA x "<<m["WA"]<<nl;
    cout<<"TLE x "<<m["TLE"]<<nl;
    cout<<"RE x "<<m["RE"]<<nl;

    return 0;
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<ll> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = a[i] + b[i];
	}
	sort(begin(c), end(c), greater<ll>());

	ll score = 0;
	for (int i = 0; i < n; i++) {
		if (i & 1) {
			continue;
		}
		score += c[i];
	}
	ll bSum = accumulate(begin(b), end(b), 0LL);

	ll ans = score - bSum;
	cout << ans << endl;
	return 0;
}


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

int A[51];

int main(){
    int n,l,r;
    
    while(true){
        cin >> n >> l >> r;
        if(n == 0){
            break;
        }
        for(int i=1; i<=n; i++){
            cin >> A[i];
        }

        int counter = 0;

        for(int num=l; num<=r; num++){
            bool flag = false;
            for(int i=1; i<=n; i++){
                if(num%A[i] == 0){
                    if(i%2==1){
                        counter++;
                    }
                    flag = true;
                    break;
                }
            }
            if(flag){
                continue;
            }

            if(n%2==0){
                counter++;
            }
        }

        cout << counter << endl;
    }

    return 0;
}


Measured memory_bytes: 3016
#include <cstdio>
int main() {
    int a,b,c;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    if (a == 5 && b == 5 && c == 7) {
        printf("YES");
    } else if (a == 5 && b == 7 && c == 5) {
        printf("YES");
    } else if (a == 7 && b == 5 && c == 5) {
        printf("YES");
    } else {
        printf("NO");
    }
}


Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();//A
		int B = sc.nextInt();//B

		if(B % A == 0) {
			System.out.println(A + B);
		}else {
			System.out.println(B - A);
		}

	}



}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21972
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class DCrossing {
        private static final String YES = "Yes";
        private static final String NO = "No";

        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            for (int k = 2; k <= 448; k++) {
                if (k * (k - 1) == 2 * n) {
                    out.println(YES);
                    out.println(k);
                    List<List<Integer>> sets = new ArrayList<>(k);
                    for (int i = 0; i < k; i++) {
                        sets.add(new ArrayList<>());
                    }

                    int m = 0;
                    for (int i = 0; i < k; i++) {
                        for (int j = i + 1; j < k; j++) {
                            m++;
                            sets.get(i).add(m);
                            sets.get(j).add(m);
                        }
                    }

                    for (int i = 0; i < k; i++) {
                        out.print(sets.get(i).size());
                        for (int j = 0; j < sets.get(i).size(); j++) {
                            out.print(' ');
                            out.print(sets.get(i).get(j));
                        }
                        out.println();
                    }
                    return;
                }
            }
            out.println(NO);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 44224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, a[114514];
map<int, int> mp;
int ans;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		mp[i + 1] = a[i];
	}
	for (int i = 1; i <= n; i++) {
		if (mp[mp[i]] == i)ans++;
	}
	cout << ans / 2 << endl;
}

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

int main(){

    /*
    string str;
    cin >> str;
    vector<int> num(str.length());
    for(int i = 0; i < str.length(); i++){
       num[i] = stoi(str) / (;
    }
    */

    long long int num;
    bool flag = true;
    cin >> num;

    int diffMin = 999;
    while(flag){
        int diff = abs(num % 1000 - 753);
        if(diff < diffMin){
            diffMin = diff;
        }

        if(num < 1000){
            flag = false;
        }
        else{
            num = num / 10;
        }
    }

    cout << diffMin << endl;

}

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

int main(){
  int n,i;
  char s[200];
  char t[200];
  char r;
  char ans[300];
  int tsp = 0;
  int ssp = 0;
  int anssp = 0;

  scanf("%d", &n);
  scanf("%s %s", s, t);

  while(tsp < n){
    printf("%c", s[ssp]);
    ssp++;
    printf("%c", t[tsp]);
    tsp++;
  }

  printf("\n");
  return 0;
}


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

ll memo[2020][2020];
int n;
vector<ll> a;

ll rec(int l, int len){
  if(memo[l][len]>=0)return memo[l][len];
  if(len <= 1)return 0;

  int L = l, R = (l+len-1)%n;
  if(a[L]<a[R])R = (R+n-1)%n;
  else L = (L+1)%n;

  return memo[l][len] = max(a[L]+rec((L+1)%n,len-2) , a[R]+rec(L,len-2));
}

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

  memset(memo,-1,sizeof(memo));
  ll res = 0;
  for(int i=0;i<n;i++){
    res = max( res, rec((i+1)%n,n-1) + a[i] );
  }
  cout << res << endl;
}

Measured memory_bytes: 33156
#include<iostream>
#include<algorithm>
using namespace std;
int t[10001];
int f(int x){
  if(t[x]!=0)return t[x];
  return t[x]=f(x-1)+x;
}
int main(){
  int n;
  t[0]=1;
  while(cin>>n){
    cout <<f(n)<<endl;
  }
  return 0;
}

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

int main()
{
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    //[0]index, [1]value
    int max[2] = {0, 1};
    int next_max[2] = {0, 1};
    for(int i = 0; i < n; i++){
        if(a[i] > max[1]){
            next_max[0] = max[0];
            next_max[1] = max[1];
            max[0] = i;
            max[1] = a[i];
        } else if(a[i] > next_max[1]){
            next_max[0] = i;
            next_max[1] = a[i];
        }
    }
    for(int i = 0; i < n; i++){
        if(i == max[0]){
            printf("%d\n", next_max[1]);
        } else {
            printf("%d\n", max[1]);
        }
    }
    return 0;
}

Measured memory_bytes: 2432
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n, m = map(int, input().split())
s = input()
t = input()

ans = lcm(n, m)

chk = {}

for i in range(n):
    d = ans//n
    chk[i*d] = s[i]
for i in range(m):
    d = ans//m
    if i*d in chk and chk[i*d] != t[i]:
        print(-1)
        exit()
print(ans)



Measured memory_bytes: 15396
n=int(input())
a=list(map(int,input().split()))
l=0
r=1
t=a[0]
ans=0
 
while l<n:
  if r==n:
    ans+=r-l
    l+=1
    continue
  if t+a[r]==t^a[r]:
    t+=a[r]
    r+=1
  else:
    ans+=r-l
    t-=a[l]
    l+=1
print(ans)

Measured memory_bytes: 32116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    int r = 0;
    ll sum = 0;
    for (int l = 0; l < n; l++) {
        while (r < n) {
            if ((sum^a[r]) != (sum+a[r])) break;
            sum += a[r];
            r++;
        }
        ans += r-l;
        sum -= a[l];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	string s;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='C'){
			for(int j=i; j<s.size(); j++){
				if(s[j]=='F'){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


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

using namespace std;

template <typename T>
T random(T lo, T hi) {
  std::random_device rd;
  std::uniform_int_distribution<T> uid(lo, hi);
  return uid(rd);
}

class RollingHash {
 private:
  const uint64_t mod = (UINT64_C(1) << 61) - 1;
  static inline uint64_t base = random(UINT64_C(10007), UINT64_C(1) << 28);
  std::vector<uint64_t> hashes, pows;

  uint64_t add(uint64_t a, uint64_t b) const {
    a += b;
    if (a >= mod) a -= mod;
    return a;
  }

  uint64_t sub(uint64_t a, uint64_t b) const {
    if (a < b) a += mod;
    a -= b;
    return a;
  }

  uint64_t mul(uint64_t a, uint64_t b) const {
    uint64_t ah = a >> 31, al = a & ((UINT64_C(1) << 31) - 1), bh = b >> 31,
             bl = b & ((UINT64_C(1) << 31) - 1), m = ah * bl + al * bh,
             v = (ah * bh << 1) + (m >> 30) +
                 ((m & ((UINT64_C(1) << 30) - 1)) << 31) + al * bl;
    v = (v & ((UINT64_C(1) << 61) - 1)) + (v >> 61);
    return v;
  }

 public:
  template <typename T>
  RollingHash(const T &S) : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) {
    pows[0] = 1;
    for (size_t i = 0; i < S.size(); i++) {
      pows[i + 1] = mul(pows[i], base);
      hashes[i + 1] = add(mul(hashes[i], base), S[i]);
    }
  }

  template <typename T>
  RollingHash(const T &S, const uint64_t base)
      : hashes(S.size() + 1, 0), pows(S.size() + 1, 0) {
    pows[0] = 1;
    for (size_t i = 0; i < S.size(); i++) {
      pows[i + 1] = mul(pows[i], base);
      hashes[i + 1] = add(mul(hashes[i], base), S[i]);
    }
  }

  // S[l, r)
  uint64_t slice(int l, int r) const {
    return sub(hashes[r], mul(hashes[l], pows[r - l]));
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  vector<int> S(N), T(N);
  for (int i = 0; i < N; i++) {
    S[i] = A[i] ^ A[(i + 1) % N];
    T[i] = B[i] ^ B[(i + 1) % N];
  }
  for (int i = 0; i < N; i++) {
    S.emplace_back(S[i]);
  }
  RollingHash rhs(S), rht(T);
  for (int i = 0; i < N; i++) {
    if (rhs.slice(i, i + N) == rht.slice(0, N)) {
      cout << i << ' ' << (A[i] ^ B[0]) << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 17008
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		char[] chars = n.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] == (i % 2 == 0 ? 'L' : 'R')) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int a,b,c,d;
	cin >> a>>b>>c>>d;
	if((a+d-1)/d>=(c+b-1)/b){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3636
N = int(input())

def dig(n):
    l = len(bin(abs(n)))-2
    l += int(n * ((-1)**l)>0)
    return l

def main(n):
    if n == 0:
        return "0"
    s = ""
    while n!=0:
        if n%2:
            s = "1" + s
            n -= 1
        else:
            s = "0" + s
        n //= -2
    return s

print(main(N))

Measured memory_bytes: 3064
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var y = int.Parse(Console.ReadLine().Trim());
            var bmax = 0; var kinrimax = 0d;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var b = int.Parse(line[0]);
                var r = int.Parse(line[1]);
                var t = int.Parse(line[2]);
                double    kinri;
                if (t == 1) kinri = 1 + y * r / 100d;
                else kinri = Math.Pow(1 + r / 100d, y);
                if (kinri > kinrimax) { kinrimax = kinri; bmax = b; }
            }
            Console.WriteLine(bmax);
        }
    }
}

Measured memory_bytes: 9512
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String s = scan.next();
		String a = "";
		String okikae = "";

		for(int i=0;i<s.length();i++) {

			okikae = s.substring(i,i+1);
			 okikae = "x";
			 a = a+ okikae;

		}

		System.out.println(a);

		scan.close();

	}

}


Measured memory_bytes: 23124
N=int(input())
S=input()
ans=0
for i in range(N+1):
  bns=0
  dp=[0]*26
  bp=[0]*26
  a=S[:i]
  b=S[i:]
  a=sorted(a)
  b=sorted(b)
  for j in range(len(a)):
    dp[ord(a[j])-97]+=1
  for k in range(len(b)):
    bp[ord(b[k])-97]+=1
  for l in range(26):
    if min(dp[l],bp[l])>0:
      bns+=1
  ans=max(ans,bns)
print(ans)

Measured memory_bytes: 9120
use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;


const INF: i64 = 1_000_000_000;


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    /*
    let mut xss = vec![vec![0; 3]; 4];
    println!("{:?}", xss);
    xss[1][2] = 3;
    println!("{:?}", xss);
    */

    let n = sc.read();
    let mut pos0 = vec![0; n];
    let mut pos1 = vec![0; n];
    for i in 0..2*n {
        let c = sc.read::<String>().chars().next().unwrap();
        let a = sc.read::<i64>() - 1;
        (*match c {
            'W' => &mut pos0,
            _   => &mut pos1,
        })[a as usize] = i;
    }
    // println!("{:?}", pos0);
    // println!("{:?}", pos1);

    let mut counts0 = Vec::new();
    let mut cnt = vec![0; 2*n];
    for &p in pos0.iter() {
        counts0.push(cnt.clone());
        for k in p..2*n {
            cnt[k] += 1;
        }
    }
    counts0.push(cnt);

    let mut counts1 = Vec::new();
    let mut cnt = vec![0; 2*n];
    for &p in pos1.iter() {
        counts1.push(cnt.clone());
        for k in p..2*n {
            cnt[k] += 1;
        }
    }
    counts1.push(cnt);

    let mut dp = vec![vec![INF; n+1]; n+1];
    dp[0][0] = 0;
    for i in 0..n+1 {
        for j in 0..n+1 {
            let now = dp[i][j];
            if i < n {
                let pos = pos0[i];
                let dst = &mut dp[i+1][j];
                *dst = cmp::min(*dst, now + pos as i64 - counts0[i][pos] - counts1[j][pos]);
            }
            if j < n {
                let pos = pos1[j];
                let dst = &mut dp[i][j+1];
                *dst = cmp::min(*dst, now + pos as i64 - counts0[i][pos] - counts1[j][pos]);
            }
        }
    }
    // println!("{:?}", counts0);
    // println!("{:?}", counts1);
    // println!("{:?}", dp);

    println!("{}", dp[n][n]);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 192764
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int m, n, sum=0;
    scanf("%d%d", &m, &n);
    int *p;
    p=(int*)malloc(n*sizeof(int));
    int i;
    for(i=0; i<n; i++){
        scanf("%d", &p[i]);
        sum+=p[i];
    }
    int ans=m-sum;
    if(ans>-1){
        printf("%d\n", ans);
    }
    else{
        printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 1752
N = int(input())
c = list(input())


ans = 0
left_W = 0
right_R =c.count("R")

if c.count("R")==0 or c.count("W") == 0:
    ans = 0
for n in range (N):
    if c[n] == "R":
        right_R -= 1
    else:
        left_W += 1


    if left_W == right_R:
        ans = right_R
        break
print(ans)



Measured memory_bytes: 10700
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (ll)1e9+1
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll mod=1e9+7;    

ll power(ll b,ll p)
{
    ll r=1ll;
    while(p)
    {
        if(p&1ll)
            r*=b, r%=mod;
        b*=b, b%=mod;
        p>>=1ll;
    }   
    return r;
}

ll modInverse(ll x)
{
    return power(x,mod-2ll);
}   

signed main()
{
    warmup
    
    int n,k;
    cin>>n>>k;
    int a[n+1],i,j;
    for(i=1;i<=n;++i)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(i=1;i<=n;++i)
        if(a[i]<0)
            a[i]+=mod;

    ll ans=a[k],cnt=1,x=1;
    for(i=k+1;i<=n; ++i, ++x)
    {
        cnt*=(i-1);
        cnt%=mod;
        cnt*=modInverse(x);
        cnt%=mod;
        
        ans+=((cnt*a[i])%mod);
        if(ans>mod)
            ans-=mod;
    }   
    ans-=a[n-k+1];
    if(ans<0)
        ans+=mod;
    cnt=1, x=1;
    for(i=n-k;i>=1; --i, ++x)
    {
        cnt*=(n-i);
        cnt%=mod;
        cnt*=modInverse(x);
        cnt%=mod;
        
        ans-=((cnt*a[i])%mod);
        if(ans<0)
            ans+=mod;
    }   
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n,m,t,mt,tt;
  while(cin>>n){
    if(n==0) break;
    mt = 0;
    tt = 0;
    for(int i=0;i<n;i++){
      cin >> m >> t;
      if(m>t) mt += (m+t);
      else if(t>m) tt += (m+t);
      else{
	mt += m;
	tt += t;
      }
    }
    cout << mt << ' ' << tt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
house = Array.new(4,0).map { Array.new(3,0).map { Array.new(10,0) } }
n = gets.to_i
n.times do |i|
  b, f, r, v = gets.chomp.split(" ").map(&:to_i)
  house[b-1][f-1][r-1] += v
end

house.size.times do |i|
  house[i].each do |j|
    puts " " + j.join(" ")
  end
  puts "#" * 20 if i + 1 < house.size
end

Measured memory_bytes: 8732
def mod_until_one(a, m)
  dot = -1
  count = 0
  while dot != 1
    dot = 1 if dot == -1
    dot = (a * dot) % m
    count += 1
  end
  count
end

def electro_fly(fly_data)
  count1, count2, count3 = (0..4).step(2).map{ |i| fly_data[i,2] }.map{ |d| mod_until_one(*d) }
  count1.lcm count2.lcm count3
end

loop do
  fly_data = gets.chomp.split.map(&:to_i)
  break if fly_data.all?(&:zero?)
  puts electro_fly(fly_data)
end

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

public class Main{

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

	private Scanner scan;
	private int n;

	private void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();

		for(;n != 0; n--) {
			looprun();
		}

		scan.close();
	}

	private int outcount,point;
	private int runner[] = new int[3];
	private String result;

	private void looprun() {
		outcount = 0;
		point = 0;
		Arrays.fill(runner,0);

		while(outcount < 3) {
			result = scan.next();

			if(result == null) {
				System.out.println("ぬるぽ");
			}else {
				switch(result) {
				case "HIT":
					for(int i = 2;i >= 0;i--) {
						if(runner[i] == 1) {
							runner[i] = 0;
							if(i == 2) {
								point++;
							}else {
								runner[i + 1] = 1;
							}
						}
					}
					runner[0] = 1;
					break;

				case "HOMERUN":
					point += Arrays.stream(runner).sum() + 1;
					Arrays.fill(runner,0);
					break;

				case "OUT":
					outcount++;
					break;

				default:
					break;
				}
			}
		}

		System.out.println(point);
	}
}


Measured memory_bytes: 32068
class Node
  attr_accessor :parent, :size
  def initialize(n)
    @parent = n
    @size = 1
  end
end

class UnionFindTree
  def initialize(n)
    @nodes = (0..n).map { |i| Node.new(i) }
  end

  def find(x)
    return x if @nodes[x].parent == x
    @nodes[x].parent = find(@nodes[x].parent)
  end

  def unite(a, b)
    pa = find(a)
    pb = find(b)
    return if pa == pb

    if @nodes[pa].size < @nodes[pb].size
      @nodes[pa].parent = pb
    else
      @nodes[pb].parent = pa
    end

    tmp = @nodes[pa].size + @nodes[pb].size
    @nodes[pa].size = tmp
    @nodes[pb].size = tmp

  end

  def same?(a, b)
    find(a) == find(b)
  end

  def size(x)
    return @nodes[find(x)].size
  end

end


N, M = gets.split.map(&:to_i)
A =[]
B=[]

for i in 0..M-1 do
  A[i], B[i] = gets.split.map(&:to_i)
end

ans = Array.new(M)
cur = N*(N-1)/2
uft = UnionFindTree.new(N)


for i in 0..M-1 do

  ans[i] = cur

  a = A[M-1-i]
  b = B[M-1-i]

  next if uft.same?(a,b)

  sa = uft.size(a)
  sb = uft.size(b)

  cur -= sa*sb

  uft.unite(a,b)

end


for i in 0..M-1 do
  puts ans[M-1-i]
end


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

struct In{
	int a, b, c, d;
};

int ans = 0;
vi A;
vector<bool> seen;
void dfs(int &m, int &n, int depth, vector<In> &in, int &q){
	if(depth == n+1){
		//for_each(all(A), [](auto t){ cerr<< t; });
		//cerr << endl;
		int res = 0;
		for(int i = 0; i < q; i++){
			if(A[in[i].b] - A[in[i].a] != in[i].c) continue;
			res += in[i].d;
		}
		ans = max(ans, res);
		return;
	}
	for(int i = 1; i <= m; i++){
		if(A[depth-1] > i) continue;
		A[depth] = i;
		dfs(m, n, depth+1, in, q);
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, m, q;
	cin >> n >> m >> q;
	vector<In> in(q);
	vi c(q), d(q);
	rep(i, q)
		cin >> in[i].a >> in[i].b >> in[i].c >> in[i].d;

	A.resize(n+1, 1);
	seen.resize(n, false);
	dfs(m, n, 1, in, q);

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

Measured memory_bytes: 3664
#include<stdio.h>
#include<string.h>
int main()
{
    char w[101], ch;
    int i, j, ara[27], c, flag;
    for(i=0; i<=27; i++) ara[i] = 0;
    scanf("%s", w);
    j = strlen(w);
    for(i=0; i<j; i++)
    {
       c = w[i] - 'a' + 1;
       ara[c]++;
    }
    flag = 1;
    for(i=1; i<=26; i++)
    {
        if(ara[i] % 2 != 0){
            flag = 0;
            break;
        }
    }

    if(flag == 1) printf("Yes\n");
    else printf("No\n");
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

vector<int> dict;
int dfs (const Graph &G, int v, int to){
    dict[to] = v;

    for(int next_v: G[to]){
        if(dict[next_v] >= 0) continue;
        dfs(G, to, next_v);
    }  
}

int main() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dict.resize(n);
    dict.assign(n,-1);

    queue<int> que;
    dict[0] = 0, que.push(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (dict[nv] == -1) {
                dict[nv] = v;
                que.push(nv);
            }
        }
    }


    vector<int> ans(n);
    for(int i = 1; i<n; i++){
        if(dict[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
        ans[i] = dict[i];
    }
    cout << "Yes" << endl;
    for(int i=1; i<n; i++){
        cout << dict[i] + 1 << endl;
    }

}

Measured memory_bytes: 10568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))
#define INF INT_MAX

using namespace std;
using LL=long long;

int main(){
    int n,q,t;
    string name;
    queue<pair<string,int> > Q;
    cin>>n>>q;
    LP(i,n){
        cin>>name>>t;
        Q.push(make_pair(name,t));
    }
    pair<string,int> u;
    int elaps=0,a;
    while(!Q.empty()){
        u=Q.front();Q.pop();
        a=min(u.second,q);
        u.second-=a;
        elaps+=a;
        if(u.second>0){
            Q.push(u);
        }
        else{
            cout<<u.first<<" "<<elaps<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 6336
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main () {

	string s; cin >> s;

	int w; cin >> w;

	for (int i = 0; i < s.size(); i += w) {
		cout << s[i];
	}

	cout << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

unsigned GetDigit(ull num) {
    return log10(num);
}

void nextPernutationPrint(const vector<int>& v) {
    for_each(v.begin(), v.end(), [](int x) { cout << x << " "; });
    cout << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> T(N), P(N), Q(N);
    rep(i, N) {
        T[i] = i + 1;
        cin >> P[i];
    }
    rep(i, N) {
        cin >> Q[i];
    }

    int cnt = 1, pValue = 0, qValue = 0;
    do {
        bool pFlag = true, qFlag = true;
        for (int i = 0; i < N; i++) {
            if (T[i] != P[i]) {
                pFlag = false;
            }
            if (T[i] != Q[i]) {
                qFlag = false;
            }
        }
        if (pFlag) {
            pValue = cnt;
        }

        if (qFlag) {
            qValue = cnt;
        }

        cnt++;
    } while (next_permutation(T.begin(), T.end()));

    cout << abs(pValue - qValue) << endl;
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		
		if(a.equals("H")) {
			//aは正直
			if(b.equals("H")) {
				//a「tは正直]
				System.out.println("H");
			} else {
				System.out.println("D");
			}
		} else {
			//aは嘘つき
			if(b.equals("H")) {
				System.out.println("D");
			} else {
				System.out.println("H");
			}
		}
	}
}


Measured memory_bytes: 35536
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e7+5;
const int M=100005;
const ll LINF=1e16;
const int INF=0x3f3f3f3f;
const ull sed=31;
const ll mod=1e9+7;
const double eps=1e-8;
typedef pair<int,int>P;
typedef pair<double,double>Pd;

ll inv[N],fac[N];

ll qpow(ll a,ll b)
{
    ll ret=1;
    while(b)
    {
        if(b&1) ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}

void init()
{
    fac[0]=1;
    for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
    inv[N-1]=qpow(fac[N-1],mod-2);
    for(int i=N-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}

ll C(ll a,ll b)
{
    if(b>a) return 0;
    if(b==0) return 1;
    return fac[a]*inv[b]%mod*inv[a-b]%mod;
}

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(x<0 || y<0 || (x+y)%3)
    {
        puts("0");
        return 0;
    }
    init();
    int n=(2*y-x)/3,m=(2*x-y)/3;
    if(n<0 || m<0)
    {
        puts("0");
        return 0;
    }
    printf("%lld\n",C(n+m,n));
    return 0;
}


Measured memory_bytes: 156672
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  int n;
  cin >> n;
  cout << n + pow(n, 2) + pow(n, 3);
  return 0;
} //good night.

Measured memory_bytes: 4308
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  while(getline(cin,s),s!="."){
    stack<char> a;
    int i=0;
    for(;i<s.size();++i){
      if(!(s[i]-'(')||!(s[i]-'['))a.push(s[i]);
      if(s[i]==')')if(a.empty()||a.top()!='(')break;else a.pop();
      if(s[i]==']')if(a.empty()||a.top()!='[')break;else a.pop();
    }cout<<(i!=s.size()||!a.empty()?"no":"yes")<<endl;
  }
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    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;
    }
}
// 二項係数計算
long long 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;
}

int main() {
    int n,m;
    cin >> n >> m;
    if (n==m) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  
while(1){
  
  int a,b; char op;
  
  scanf("%d %c %d", &a, &op, &b);
  
  if(op=='?'){ break; }
  
  if(op=='+'){
    printf("%d\n",a+b);
    }
  else if(op=='-'){
    printf("%d\n",a-b);
    }
  else if(op=='*'){
    printf("%d\n",a*b);
    }
  else if(op=='/'){
    printf("%d\n",a/b);
    }
  
  }

}

Measured memory_bytes: 1188
n = int(input())
a = [int(i) for i in input().split()]
c = 0
d = 0
for i in range(n):
    for j in range(c, n):
        if i + 1 == a[j]:
            c = j
            d += 1
            break
    else:
        break
    if c == n - 1:
        break
if 1 not in a:
    print(-1)
else:
    print(n - d)

Measured memory_bytes: 25768
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> red(n);
  vector<pair<int, int>> blue(n);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    red[i] = {x, y};
  }
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    blue[i] = {x, y};
  }

  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());
  vector<bool> used(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    const int c = blue[i].first;
    const int d = blue[i].second;

    int max_y = -1;
    int min_j = -1;
    for (int j = 0; j < n; j++) {
      const int a = red[j].first;
      const int b = red[j].second;
      if (c < a || d < b) {
        continue;
      }
      if (max_y < b && !used[j]) {
        max_y = b;
        min_j = j;
      }
    }
    if (min_j >= 0) {
      used[min_j] = true;
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#dice3
def r(D,s):
    if s==0:
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif s==2:
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif s==3:
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif s==1:
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t
    elif s==4:
        D=r(r(D,1),1)
    return D
def ch(C,D):
    k=0
    while k<6 and C[k]==D[k]:
        k+=1
    if k==6:
        return 1
    else:
        return 0
C=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
nd=0
if ch(C,D)==1:
    nd=1
i=0
while i<4 and nd==0:
    D=r(D,i)
    j=i+1
    j%=4
    k=0
    if ch(C,D)==1:
        nd=1
 #   if i==0:
    #    print(D)
    while k<3 and nd==0:
        D=r(D,j)
        if ch(C,D)==1:
            nd=1
        k+=1
  #      if i==0:
        #    print(D)
    D=r(D,j)
 #   if i==0:
   #     print(D)
    m=i+2
    m%=4
 #   if i==0:
    #    print(m)    
    D=r(D,m)
 #   if i==0:
 #       print(D)
    i+=1
i=0
while nd==0 and i<4:
    D=r(D,0)
    D=r(D,1)
    D=r(D,0)
    if ch(C,D)==1:
        nd=1
    D=r(r(D,0),0)
    if ch(C,D)==1:
        nd=1
    i+=1
if nd==1:
    p="Yes"
else:
    p="No"
print(p)

Measured memory_bytes: 7912
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let mut an = read_vec::<i64>();
    let mut ans = 0;
    loop {
        an.sort();
        if an[0] == an[1] && an[1] == an[2]{
            println!("{}",ans );
            return;
        }else if an[0] != an[1] && an[1] == an[2]{
            an[0] += 2;
            ans += 1;
        }else if an[0] != an[1] && an[1] != an[2]{
            an[0] += 1;
            an[1] += 1;
            ans += 1;
        }else{
            an[0] += 1;
            an[1] += 1;
            ans += 1;
        }
    }
}

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

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

int main() {
  ll K,ans=0,temp;
  cin >> K;
 
  for(int a=1;a<K+1;a++){
    for(int b=1;b<K+1;b++){
      for(int c=1;c<K+1;c++){ 
        temp = gcd(gcd(a,b),gcd(b,c));
        ans = ans + temp;
      }
    }
  }

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

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = int64_t;
int main() {
    Int N, X;
    cin >> N >> X;
    vector<Int> m(N);
    for (auto& i : m) {
        cin >> i;
        X -= i;
    }
    cout << N + X / *min_element(m.cbegin(), m.cend()) << endl;
}


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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int sum = 0, count = 0;
	while (a > 0 && count < k) {
		sum++;
		count++;
		a--;
	}

	while (b > 0 && count < k) {
		count++;
		b--;
	}

	while(c > 0 && count < k) {
		sum--;
		c--;
		count++;
	}

	cout << sum << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N-1);
  rep(i,N)
  {
    cin >> A[i];
  }
  rep(i,N)
  {
    cin >> B[i];
  }
  rep(i,N-1)
  {
    cin >> C[i];
  }
  int sum = 0;
  rep(i,N)
  {
    sum += B[i];
  }
  rep(i,N)
  {
    if(A[i]+1==A[i+1])
    {
      sum += C[A[i]-1];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {

	int a,b;
	cin >> a >> b;
	

	int bb = b * 2;


	int ans = a - bb;

	if (ans < 0) {
		cout << 0 << endl;

	}
	else {
		cout << ans<< endl;

	}



}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

int main() {

    int N, X, A, tmp1, tmp2, i = 0, ans = 0, cst = 1;

    std::cin >> N;

    int d[N];

    while(std::cin >> tmp1){
        d[i] = tmp1;
        i++;
        if(i >= N){
            break;
        }
    }

    std::sort(d, d + N);

    int div_p = N/2;

    if(d[div_p - 1] == d[div_p]){
        std::cout << ans << std::endl;
        return 0;
    }else{
        ans = d[div_p] - d[div_p - 1];
    }

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

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define all(arr) arr.begin(),arr.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
/*int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;*/

void solve()
{
	int n;
	cin>>n;
	cout<<(n)*(n-1)/2<<endl;
}

int32_t main()
{
	FastIO; PRECISION;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


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

int main()
{
    int aend=0, bstart=0,ab = 0 ,both=0;

    int num;
    cin >> num;

    string str;
    string stra = "A";
    string strb = "B";
    string strab = "AB";

    int ans=0;

    for(int i=0;i<num;i++){
        cin >> str;
        size_t size = str.length();
        int currenta=0,currentb=0;
        
        for(int j=0;j<=size-2;j++){
            if(str.compare(j,2,strab)==0){
                ab++;
            }
        }

        if(str.compare(0,1,strb)==0){
            currentb = 1;
        }
        if(str.compare(size-1,1,stra)==0){
            currenta = 1;
        }

        if((currenta==1)&&(currentb==1)){
            both ++;
        }
        aend += currenta;
        bstart += currentb;
    }

    ans += ab;

    if((aend==bstart)&&(aend==both)&&(aend>0)){
        ans --;
    }

    ans += min(aend,bstart);

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256