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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

bool dfs(const vvi& g,int u,int c,vi& color,int& x,int& y)
{
	if(color[u]!=-1)
		return color[u]==c;
	color[u]=c;
	(c==0?x:y)++;
	for(int v:g[u])
		if(!dfs(g,v,!c,color,x,y))
			return false;
	return true;
}

ll solve(const vvi& g)
{
	int n=g.size();
	
	vector<pii> ps;
	{
		vi color(n,-1);
		rep(i,n) if(color[i]==-1){
			int x=0,y=0;
			if(!dfs(g,i,0,color,x,y))
				return -1;
			ps.emplace_back(x,y);
		}
	}
	
	bitset<100001> b;
	b[0]=1;
	for(pii p:ps)
		b=(b<<p.first)|(b<<p.second);
	
	ll mx=0;
	rep(i,b.size()) if(b[i])
		mx=max(mx,ll(i)*(n-i));
	
	int e=0;
	rep(i,n) e+=g[i].size();
	
	return mx-e/2;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vvi g(n);
		for(int i=0;i<m;i++){
			int u,v; cin>>u>>v; u--,v--;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		cout<<solve(g)<<endl;
	}
}

Measured memory_bytes: 7592
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long s; cin >> s;
	long long mod = 1e9;
	long long x, y;
	x = (mod - s % mod) % mod;
	y = (s + x) / mod;
	assert(mod * y - x == s);
	assert(x <= 1e9 || y <= 1e9);
	cout << "0 0 1000000000 1 " << x << " " << y << endl;
	return 0;
}


Measured memory_bytes: 3504
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int i;
	int cnt=0;
	int count=0;
	for(i=1;i<=N;i+=2){
		for(int j=1;j<=i;j++){
			if(i%j==0){
				cnt++;
			}
		}
		if(cnt==8){
			count++;
		}
		cnt=0;
	}
	cout<<count<<endl;
}


Measured memory_bytes: 256
// review
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
const int MAXN = 1e5+10;
const int INF = 1e5+10;

int n, m;
P a[MAXN];

void solve() {
  sort(a, a + m, greater<P>());
  int cnt = 0;
  int cur = INF;
  for (int i=0;i<m;i++) {
    if (a[i].second <= cur) {
      cnt++;
      cur = a[i].first;
    }
  }
  cout << cnt << endl;
}

int main() {
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    cin >> a[i].first >> a[i].second;
  }
  solve();
}


Measured memory_bytes: 1024
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}

	void run() {
		FastScanner sc = new FastScanner();
		int N=sc.nextInt();
		int[] A=new int[N];
		int[] cnt=new int[N];
		for(int i=0;i<N;++i) {
			A[i]=sc.nextInt();
			--A[i];
			++cnt[A[i]];
		}
		long base=0;
		for(int i=0;i<N;++i) {
			base+=(long)cnt[i]*(cnt[i]-1)/2;
		}
		PrintWriter pw=new PrintWriter(System.out);
		for(int i=0;i<N;++i) {
			long ans=base-(long)cnt[A[i]]*(cnt[A[i]]-1)/2+(long)(cnt[A[i]]-1)*(cnt[A[i]]-2)/2;
			pw.println(ans);
		}
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); 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() {
    	return (int)nextLong();
    }
}

Measured memory_bytes: 38600
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
vi pat;
int n, m;
 
int solve(vi data, int st);

signed main()
{
    cin >> n >> m;
    vi input(n), fir(n), sec(n);
    int one = 0, zero = 0;
    rep(i, n) {
        cin >> input[i];
        fir[i] = sec[i] = input[i];
    }
    rep(i, m) {
        int tmp;
        cin >> tmp;
        pat.pb(tmp);
    }

    cout << min(solve(fir, 0), solve(sec, 1)) << endl;

    return 0;
}

int solve(vi data, int st)
{
    int pos = 0, ret = 0;
    rep(i, m) {
        int cnt = 0;
        while (cnt != pat[i]) {
            if (data[pos] == st) {
                cnt++;
                pos++;
            } else {
                bool fl = false;
                for (int j = pos; j + 1 < n; j++) {
                    if (data[j+1] == st) {
                        int tmp = data[j];
                        data[j] = data[j+1];
                        data[j+1] = tmp;
                        ret++;
                        fl = true;
                        break;
                    }
                }
                if (!fl) {
                    return INF;
                }
            }
        }
        st = (st + 1) % 2;
    }
    return ret;
}

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

S = []
for i in range(N):
    S.append(input())

count = {}
ans = 0

for s in S:
    s=str(sorted(s))
    if s in count:
        count[s] += 1
    else:
        count[s] = 1

ans = 0
for c in count.values():
    ans += c*(c-1)//2
print(ans)

Measured memory_bytes: 29200
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a;
  cin>>a;
  if (a>=30) {
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}

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


Measured memory_bytes: 2560
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static int W = 0;
    static int H = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            String s = sc.next();
            if ("#".equals(s)) {
                break;
            }
            int y1 = sc.nextInt() - 1;
            int x1 = sc.nextInt() - 1;
            int y2 = sc.nextInt() - 1;
            int x2 = sc.nextInt() - 1;
            int[][] map = parse(s);
            // arrayDump(map);
            map[y1][x1] = 0;
            map[y2][x2] = 1;
            // arrayDump(map);
            System.out.println(serialize(map));
        }
    }

    public static void arrayDump(int[][] a) {
        for (int i = 0, l = a.length; i < l; i++) {
            for (int j = 0, l2 = a[0].length; j < l2; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }

    public static int[][] parse(String s) {
        String[] lines = s.split("/");
        ArrayList<ArrayList<Integer>> map = new ArrayList<>();
        for (String line : lines) {
            ArrayList<Integer> l = new ArrayList<>();
            for (int i = 0; i < line.length(); i++) {
                char c = line.charAt(i);
                if ('0' <= c && c <= '9') {
                    int n = Integer.valueOf(c + "");
                    for (int j = 0; j < n; j++) {
                        l.add(0);
                    }
                } else {
                    l.add(1);
                }
            }
            map.add(l);
        }
        int[][] mm = new int[lines.length][map.get(0).size()];
        for (int i = 0; i < lines.length; i++) {
            for (int j = 0; j < map.get(0).size(); j++) {
                mm[i][j] = map.get(i).get(j);
            }
        }
        return mm;
    }

    public static String serialize(int[][] a) {
        String[] lines = new String[a.length];
        for (int i = 0; i < a.length; i++) {
            String line = "";
            int k = 0;
            for (int j = 0; j < a[0].length; j++) {
                if (a[i][j] == 0) {
                    k++;
                } else {
                    if (k > 0) {
                        line += String.valueOf(k);
                        k = 0;
                    }
                    line += "b";
                }
            }
            if (k > 0) {
                line += String.valueOf(k);
            }
            lines[i] = line;
        }
        return String.join("/", lines);
    }
}

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

#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

const ll mod = 1e9+7;
const ll N = 2e6 + 123;
ll fact[N];

ll mpow(ll x, ll n) {
	if(n == 0) return 1;
	ll res = mpow(x, n/2);
	res = res * res % mod;
	if(n % 2 == 1) res = res * x % mod;
	return res;
}

ll inverse(ll x) {
	return mpow(x, mod-2);
}

void solve(void) {

	ll x, y;
	cin >> x >> y;
	
	fact[0] = 1;
	for(ll i = 1; i < N; i++) {
		fact[i] = fact[i-1] * i % mod;
	}

	
	if((2*x-y) % 3 || (2*y-x) % 3 || (2*y-x) < 0 || (2*x-y) < 0) {
		cout << 0 << '\n';
	} else {
		ll a = (2*x-y)/3;
		ll b = (2*y-x)/3;
		ll ans = fact[a+b] * inverse(fact[a]) % mod * inverse(fact[b]) % mod;
		cout << ans << '\n';
	}


}

int main(void) {

	solve();
	return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	char c=s[0];
	for (int i = 1; i < s.size(); i++)
	{
		if (c==s[i])
		{
			cout << "Bad" << endl;
			return 0;
		}
		c = s[i];
	}
	cout << "Good" << endl;
	return 0;
}

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

int main() {
  string str; cin >> str;
  int cnt = 0;
  for ( int i = 0; i < str.length(); i++ ) {
    if ( str[i] == '1' ) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let (n,m):(u32,u32)=(read(),read());

    println!("{}",n*(n-1)/2+m*(m-1)/2);
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n);
  vector<ll> cnt(n);
  rep(i, n) {
    cin >> A[i];
    cnt[--A[i]]++;
  }
  ll sum = 0;
  rep(i, n) sum += cnt[i] * (cnt[i]-1) / 2;
  vector<ll> ans(n);
  rep(i, n) {
    ans[i] = sum - cnt[i] * (cnt[i]-1) / 2 + (cnt[i]-1) * (cnt[i]-2) / 2;
  }
  rep(i, n) cout << ans[A[i]] << "\n";
  return 0;
}


Measured memory_bytes: 7592
k = int(input())
ans = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(ans[k-1])


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
string s[]={"light fly", "fly", "bantam", "feather", "light", "light welter","welter", "light middle", "middle", "light heavy", "heavy"};
int w[]={48,51,54,57,60,64,69,75,81,91};double a;
while(cin>>a){int i,j;
for (i=j=0; j<10; j++){if (w[i]<a) i++;else break;}
cout<<s[i]<<endl;}}

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


int main(){
  long long int x;
  cin >> x;
  long long int money=100;

  //bool flag=true;
  long long int y = 0;
  while(true){
    y++;
    money *= 1.01;
    if(money >= x)break;
  }


  cout << y << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2, class T3> void sortA_L(int N, T1 a[], T2 b[], T3 c[], void *mem = wmem){
  int i;
  pair<T1, pair<T2, T3> > *arr=(pair<T1, pair<T2, T3> > *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second.first = b[i];
    arr[i].second.second = c[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second.first;
    c[i] = arr[i].second.second;
  }
}
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
char memarr[96000000];
int A[100000], B[100000], N, wa[100000];
int main(){
  int i, j, k;
  long long res=0;
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    wa[i] = -(A[i] + B[i]);
  }
  sortA_L(N, wa, A, B);
  for(i=0;i<N;i++){
    if(i%2==0){
      res += A[i];
    }
    else{
      res -= B[i];
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// int N;
// int wa[100000], A[100000], B[100000];
// {
//   int i, j, k;
//   ll res = 0;
//   rd(N, (A,B)(N));
//   rep(i,N) wa[i] = -(A[i] + B[i]);
//   sortA(N, wa, A, B);
//   rep(i,N){
//     if(i%2==0) res += A[i]; else res -= B[i];
//   }
//   wt(res);
// }


Measured memory_bytes: 4352
import heapq

n = int(input())
ll, rr = [], []
task = []
ans = 0
for _ in range(n):
    l, r = map(int, input().split())
    heapq.heappush(ll, -l)
    heapq.heappush(rr, r)
    task.append([l, r])
maxl1, minr1 = -heapq.heappop(ll), heapq.heappop(rr)
maxl2, minr2 = -heapq.heappop(ll), heapq.heappop(rr)
for i in range(n):
    ma = maxl1 if not task[i][0] == maxl1 else maxl2
    mi = minr1 if not task[i][1] == minr1 else minr2
    ans = max(ans, task[i][1] - task[i][0] + max(0, mi - ma + 1) + 1)
for k in range(2):
    task.sort(key = lambda x : x[k])
    score = [0] * (n - 1)
    l1, r1 = task[0][0], task[0][1]
    l2, r2 = task[n - 1][0], task[n - 1][1]
    i, j = 0, n - 1
    for _ in range(n - 1):
        l1, r1 = max(l1, task[i][0]), min(r1, task[i][1])
        l2, r2 = max(l2, task[j][0]), min(r2, task[j][1])
        j -= 1
        score[i] += max(0, r1 - l1 + 1)
        score[j] += max(0, r2 - l2 + 1)
        i += 1
ans = max(ans, max(score))
print(ans)

Measured memory_bytes: 112840
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int sum = 0, mx = 0;
  rep(i, 3){
    int a;
    cin >> a;
    sum += a;
    mx = max(mx, a);
  }
  if(sum % 2 != mx % 2){
    mx++;
  }
  cout << (mx*3-sum)/2 << endl;
  // vector<int> v(3);
  // rep(snip_i, 3) cin >> v.at(snip_i);
  // sort(v.begin(), v.end());
  // int ans = 0;
  // while(1){
  //   if(v.at(1) < v.at(2)){
  //     v.at(0)++;
  //     v.at(1)++;
  //     ans++;
  //   }else if(v.at(0) <v.at(1)){
  //     v.at(0) += 2;
  //     ans++;
  //     if(v.at(0)> v.at(1)){
  //       ans++;
  //       cout << ans << endl;
  //       return 0;
  //     }
  //   }else{
  //     cout << ans << endl;
  //     return 0;
  //   }
  // }
  return 0;
}

Measured memory_bytes: 384
package main

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

func main() {
	a := readInt64Slice(2)
	b := readInt64Slice(2)
	t := readInt64()

	if a[0] < b[0] {
		aEnd := a[0] + a[1]*t
		bEnd := b[0] + b[1]*t

		if aEnd >= bEnd {
			fmt.Println("YES")
			return
		}
		fmt.Println("NO")
		return
	}

	aEnd := a[0] - a[1]*t
	bEnd := b[0] - b[1]*t

	if aEnd <= bEnd {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
	return

}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt64() int64 {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.ParseInt(t, 10, 64)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readInt64Slice(n int64) []int64 {
	s := make([]int64, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.ParseInt(t, 10, 64)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


Measured memory_bytes: 1820
n, k = map(int, input().split())
li = list(map(int, input().split()))
min_ = 10**12
for i in range(1<<n):
    max_height = li[0]
    money = 0
    can_look = 0
    li_h = []
    for j in range(n):
        if j != 0:
            max_height = max(max_height, li_h[j-1])
        #j番目が見えるようにする
        if j == 0:
            can_look += 1
            li_h.append(li[0])
            continue
        if (i>>j)&1:
            can_look += 1
            if li[j] <= max_height:
                li_h.append(max_height+1)
            else:
                li_h.append(li[j])
        else:
            li_h.append(li[j])
    if can_look >= k:
        money = sum(li_h) - sum(li)
        min_ = min(min_, money)

print(min_)

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

int main(){
	int n, m;
	cin >> n >> m;
	
	vector<int> A(m, 0);
	int ans = 0;
	
	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		for(int j=0; j<k; j++){
			int a;
			cin >> a;
			A[a-1]++;
			if(A[a-1] == n) ans++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200100
#define T 4001000
#define fo(i,a,b) for(int i=a,_E_=b;i<_E_;++i)
using namespace std;
int n,mx[N],sm[N],fa[N],res[N],s[N],ct[N],c[N],c2[N];
int son[T][2],cnt,sz[T],rt[N],opl;
vector<int> r[N];

void ins(int &x,int h,int t){
	x=++cnt;++sz[x];
	if(h==t)return;
	int m=h+t>>1;
	if(opl<=m)ins(son[x][0],h,m);else ins(son[x][1],m+1,t);
}
void merge(int &u,int v,int h,int t){
	if(!u||!v){u^=v;return;}
	sz[u]+=sz[v];
	if(h==t)return;
	int m=h+t>>1;
	merge(son[u][0],son[v][0],h,m);
	merge(son[u][1],son[v][1],m+1,t);	
}
int query(int x,int h,int t){
	if(h==t)return sz[x];
	int m=h+t>>1;
	if(opl<=m)return query(son[x][0],h,m);
	return query(son[x][1],m+1,t);
}

void dfs(int x,int M,int S,int nx){
	if(x>M)S=M,M=x;else if(x>S)S=x;
	sm[x]=S;mx[x]=M;s[x]=nx;
	if(x^M)++ct[nx];
	opl=sm[x];ins(rt[x],1,n);
	fo(i,0,r[x].size()){
		int y=r[x][i];if(y==fa[x])continue;
		fa[y]=x;dfs(y,M,S,M==x?y:nx);
		merge(rt[x],rt[y],1,n);
	}opl=sm[x];
	c[x]=query(rt[x],1,n);
	opl=sm[fa[x]];
	c2[x]=query(rt[x],1,n);
}
void calc(int x){
	if(x^1){
		res[x]=res[fa[mx[x]]]+c[mx[x]];
		if(mx[x]^x)res[x]+=ct[s[x]]-c2[s[x]];
	}
	fo(i,0,r[x].size()){
		int y=r[x][i];
		if(y==fa[x])continue;
		calc(y);
	}
}

int main(){
	scanf("%d",&n);
	fo(i,1,n){
		int x,y;scanf("%d %d",&x,&y);
		r[x].push_back(y);r[y].push_back(x);
	}dfs(1,0,0,1);
	calc(1);
	fo(i,1,n)printf("%d ",res[i+1]);
}

Measured memory_bytes: 85248
//Volume5-0514
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Test {
	public int i,j,k,r;
	Test(int i,int j,int k,int r){
		this.i=i;
		this.j=j;
		this.k=k;
		this.r=r;
	}
}

class Main {

	private static ArrayList<Test> ar = new ArrayList<Test>();

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		while(true){

			int a=sc.nextInt(),
				b=sc.nextInt(),
				c=sc.nextInt();

			if(a==0&&b==0&&c==0){break;}

			int[] parts = new int[a+b+c+1];
			Arrays.fill(parts, 2);
			int   N = sc.nextInt(),
			      i,j,k,r;

			ar.clear();
			while(N-- > 0){
				i=sc.nextInt();
				j=sc.nextInt();
				k=sc.nextInt();
				r=sc.nextInt();
				if(r==1){
					parts[i]=1;
					parts[j]=1;
					parts[k]=1;
				} else {
					ar.add(new Test(i,j,k,r));
				}
			}

			for(Test t:ar){
				if      (parts[t.j]==1&&parts[t.k]==1){parts[t.i]=0;}
				else if (parts[t.i]==1&&parts[t.k]==1){parts[t.j]=0;}
				else if (parts[t.i]==1&&parts[t.j]==1){parts[t.k]=0;}
			}

			for(int l=1;l<parts.length;l++){
				System.out.println(parts[l]);
			}
		}
	}
}

Measured memory_bytes: 28384
import java.io.*;
import java.util.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;

    public static void main(String[] args) {
        int N = in.nextInt();
        int M = in.nextInt();

        NavigableMap<Integer, Queue<Integer>> T = new TreeMap<>();
        for (int i = 0; i < N; i++) {
            T.computeIfAbsent(in.nextInt(), k -> new PriorityQueue<>(Comparator.reverseOrder()))
                    .add(in.nextInt());
        }

        int cost = 0;
        Queue<Integer> E = new PriorityQueue<>();
        Queue<Integer> Q = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 1; i <= M; i++) {
            Q.addAll(T.getOrDefault(i, E));

            if (!Q.isEmpty()) {
                cost += Q.remove();
            }
        }

        out.println(cost);
    }
}


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

int main() {
    char s[1000005];
    fgets(s, 1000005, stdin);
    int len = strlen(s);
    if (s[len-1] = '\n') len--;
    for (int i=0; i<len; i++) {
        s[i] -= '0';
    }
    int hum_1 = 0, hum_0 = 0;
    for (int i=0; i<len; i++) {
        if (i%2 == 0) {
            hum_1 += abs(s[i]-1);
            hum_0 += abs(s[i]);
        }
        else {
            hum_1 += abs(s[i]);
            hum_0 += abs(s[i]-1);
        }
    }
    int ans = (hum_1 < hum_0) ? hum_1 : hum_0;
    printf("%d\n", ans);
    return 0;
}


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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define vll vector<ll>
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define MOD 1000000007
const ll N = 2e5;

int main()
{
    speed;
    ll k,n; cin>>k>>n;
    vll a(n);
    forn(i,n) cin>>a[i];
    // vll diff(n);
    // ll sum = 0;
    // forn(i,n-1){
    // 	diff[i] = abs(a[i]-a[i+1]);
    // 	sum+=diff[i];
    // }
    // diff[n-1] = k-a[n-1]+a[0];
    // print(diff);
    // sum+=diff[n-1];
    // sort(all(diff));
    ll maxi = k-a[n-1]+a[0];
    forn(i,n-1){
    	maxi = max(maxi,a[i+1]-a[i]);
    }
    cout<<k-maxi<<endl;
    //cout<<sum-diff[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		long[] result = new long[10000];
		int index = 0;
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				long a = stdIn.nextLong();
				long b = stdIn.nextLong();
				
				result[index] = a+b;
				index++;
			}
			
			for(int i = 0; i < index; i++){
				System.out.println(result[i]);
			}
		} finally {
 			if( stdIn != null ){
 				stdIn.close();
 			}
 		}
 	}
}

Measured memory_bytes: 12000
#include <iostream>

#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::min;

constexpr long fmove(int n)
{
  return (n == 0 ? 0
          : n == 1 ? 1
          : fmove(n - 1) * 3 + 1);
}

static const long fmove_table[15] = {
  fmove(0), fmove(1), fmove(2), fmove(3), fmove(4),
  fmove(5), fmove(6), fmove(7), fmove(8), fmove(9),
  fmove(10), fmove(11), fmove(12), fmove(13), fmove(14),
};

static long
move_full(int n)
{
  return fmove_table[n];
}

static int
opposite_side(int here)
{
  return here ^ 2;
}

static long
move_all_to(int N, int M, char table[15], int base, int dest)
{
  if (base == N)
  {
    return 0;
  }
  int src = table[base];
  return (dest == src ? move_all_to(N, M, table, base + 1, dest)
          : src == 1 ? (move_all_to(N, M, table, base + 1, opposite_side(dest))
                        + 1 + move_full(N - (base + 1)) * 2)
          : dest == 1 ? (move_all_to(N, M, table, base + 1, opposite_side(src))
                         + 1 + move_full(N - (base + 1)))
          : (move_all_to(N, M, table, base + 1, dest)
             + 2 + move_full(N - (base + 1)) * 4));
}

static int
solve(int N, int M, char table[15])
{
  long count = min(move_all_to(N, M, table, 0, 0),
                   move_all_to(N, M, table, 0, 2));
  return count <= M ? int(count) : -1;
}

int
main()
{
  for (;;)
  {
    int N, M;
    char table[15];
    cin >> N >> M;
    if (N == 0 && M == 0)
    {
      break;
    }
    for (int t = 0; t < 3; t++)
    {
      int NN;
      cin >> NN;
      for (int n = 0; n < NN; n++)
      {
        int a;
        cin >> a;
        table[a - 1] = t;
      }
    }
    cout << solve(N, M, table) << endl;
  }
  return 0;
}



Measured memory_bytes: 3012
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

#maincode-------------------------------------------------
n,x,t = inl()
ans = n//x
if n % x != 0:
    ans += 1
print(ans * t)

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

int main() {
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  for (int i = A; i <= B; i++) {
    int a = i % 10;
    int b = i / 10 % 10;
    int c = i / 1000 % 10;
    int d = i / 10000 % 10;
    if (a == d && b == c) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
  
int main(){
  int n, t;
  cin >> n >> t;
  ll a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  ll ans = 0, mmax = -1, mmin = a[0];
  for(int i = 1; i < n; i++){
    ll tmp = a[i] - mmin;
    if(mmax == tmp) ans++;
    else if(mmax < tmp) ans = 1, mmax = tmp;
    mmin = min(mmin, a[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

typedef struct index_val {
  i32 k;
  i64 v;
} node;

void run (void) {
  i32 n, m, k;
  scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &n, &m, &k);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i64 *dp = ALLOC (n, i64);
  for (i32 i = 0; i < n; ++i) {
    dp[i] = a[i];
  }
  node *d = ALLOC (n, node);
  for (i32 i = 2; i <= k; ++i) {
    i32 f = 0;
    i32 b = 0;
    d[0] = (node){i - 2, dp[i - 2]};
    for (i32 j = i - 1; j < n; ++j) {
      if (d[f].k == j - m - 1) ++f;
      i64 v = d[f].v + (i64) i * a[j];
      while (f <= b && d[b].v <= dp[j]) --b;
      d[++b] = (node) {j, dp[j]};
      dp[j] = v;
    }
  }
  i64 ans = 0;
  for (i32 i = k - 1; i < n; ++i) {
    if (ans < dp[i]) {
      ans = dp[i];
    }
  }
  printf("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 3009 /// Look at me please ... that's what she said
#define MOD 1000000007
using namespace std;
const ll INF = 1e6 + 9;
ll n,t;
vector<pii> vet;
bool comp(pii a, pii b){
	if(a.first<b.first)return true;
	else if(a.first==b.first && a.second>b.second)return true;
	else return false;
}
ll dp[maxn][maxn];
ll solve(ll id, ll time){
	if(time>=t)return 0;
	if(id>=n)return 0;
	if(dp[id][time]!=-1)return dp[id][time];
	return dp[id][time]=max(solve(id+1,time+vet[id].first)+vet[id].second,solve(id+1,time));
}
int main(){
    ios::sync_with_stdio(false);
    //cin.tie(0); ///activate when submit
    cin>>n>>t;
    memset(dp,-1,sizeof dp);
    for(ll i=0;i<n;i++){
    	ll a,b;
    	cin>>a>>b;
    	vet.push_back({a,b});
    }
    sort(vet.begin(),vet.end(),comp);
    cout<<solve(0,0)<<'\n';
    return 0;
}    

Measured memory_bytes: 71296
from math import sqrt, cos, radians


def main():
    A, B, H, M = map(int, input().split())

    short = (H % 12) * 30 + float(M) / 60.0 * 30.0
    lon = M / 60 * 360
    angle = abs(short-lon)
    if angle <= 180:
        pass
    else:
        angle = 360 - angle

    ans = sqrt(A**2 + B**2 - 2 * A * B * cos(radians(angle)))

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
	string S;
	cin>>S;
    int a=0, b=0;
    for(int i=0; i<S.length(); ++i){
        if(i%2==0 && S[i]=='0'){
            a++;
        }
        if(i%2!=0 && S[i]=='1'){
            a++;
        }
    }
    for(int i=0; i<S.length(); ++i){
        if(i%2==0 && S[i]=='1'){
            b++;
        }
        if(i%2!=0 && S[i]=='0'){
            b++;
        }
    }
    cout<<min(a, b)<<endl;

    return 0;
}

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

int main()
{
    string s,t;
    int lens,lent,ans,cn,cntm;
    cin>>s;
    cin>>t;
    lens = s.length();
    lent = t.length();
    cntm=0;
    for(int i=0;i<(lens-lent+1);i++){
            cn = 0;
        for(int j=0;j<lent;j++){
            if(t[j]==s[i+j]){
                cn++;
            }
        }
    cntm = max(cntm,cn);
    }
    ans = lent-cntm;
    cout<<ans<<endl;



    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE
void solve(void)
{
  int N;cin>>N;
  vector<int> A (N+1,0);
  for (int i = 0; i < N+1; i++)
  {
     cin>>A[i];
  }
  vector<int> B (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>B[i];
  }
  int p = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    cnt += min(A[i],B[i] + p);
    p = min(0LL,A[i] - B[i] -p);
    p *= -1;
    chmin(p,B[i]);
  }
  cnt += min(A[N],p);
  cout<<cnt<<endl;
  
  return;

}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main(){
    string s; cin >> s;
    for(int i = 0; i < s.size() - 2; i++){
        if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
            cout << i+1 << " " << i + 3 << endl;
            return 0;
        }
    }
    if(s.size() == 2){
        if(s[0] == s[1]){
            cout << 1 << " " << 2 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll ans[20009];
int main()
{
	FAST
	#ifdef ayk_16
	    time_taken_start
		freopen("input.txt","rt",stdin);
		freopen("output.txt","wt",stdout);
	#endif
	ll n,s,w,v;
	cin>>n;
	pair<ll,pll> p[n];
	for(ll i=0;i<n;i++)
	{
		cin>>w>>s>>v;
		p[i].ff=w+s;
		p[i].ss.ff=s;
		p[i].ss.ss=v;
	}
	sort(p,p+n);
	ll a=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=20000;j>=0;j--)
		{
			if(j<=p[i].ss.ff)
			{
				ll z=p[i].ff-p[i].ss.ff;
				z+=j;
				if(z<=20000)
				{
					ans[z]=max(ans[z],ans[j]+p[i].ss.ss);
				}
			}
		}
	}
	for(ll i=0;i<=20000;i++)
	{
		a=max(a,ans[i]);
	}
	cout<<a;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
public class Main
{
    public static int solve(int[][] arr, int n, int prev, int[][] dp){
        if(n < 0){
            return 0;
        }
        if(dp[n][prev+1] > 0){
            return dp[n][prev+1];
        }
        int ans = Integer.MIN_VALUE;
        if(prev != 0){
            ans = Math.max(ans, arr[n][0] + solve(arr, n-1, 0, dp));
        }
        if(prev != 1){
            ans = Math.max(ans, arr[n][1] + solve(arr, n-1, 1, dp));
        }
        if(prev != 2){
            ans = Math.max(ans, arr[n][2] + solve(arr, n-1, 2, dp));
        }
        return dp[n][prev+1] = ans;
    }
	public static void main(String[] args) throws Exception{
        StringTokenizer str;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] arr = new int[n][3];
        for(int i = 0; i < arr.length; i++){
            int j = 0;
            str = new StringTokenizer(br.readLine()," ");
            while(str.hasMoreTokens()){
                arr[i][j] = Integer.parseInt(str.nextToken());
                j++;
            }
        }
        int[][] dp = new int[n+1][4];
       System.out.println(solve(arr, n-1, -1, dp));            
    }
}


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

using namespace std;

int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    for (int i=1; i<=b-a; i++)
    {
        sum+=i;
    }
    cout<<sum-b<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::{Read, stdin};
use std::str::FromStr;

fn main() {
    let s: [String; 3] = [read(), read(), read()];
    let mut ss = ["".to_string(), "".to_string(), "".to_string()];
    for i in 0..3 {
        ss[i] = s[i].chars().rev().collect();
    }
    let mut idx: usize = 0;
    loop {
        match ss[idx].pop() {
            Some(sss) => match sss {
                'a' => idx = 0,
                'b' => idx = 1,
                'c' => idx = 2,
                _ => (),
            },
            None => break,
        }
    }
    println!("{}", match idx {
        0 => "A".to_string(),
        1 => "B".to_string(),
        2 => "C".to_string(),
        _ => "".to_string(),
    });
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

const int INF = 100000000;
typedef pair<int, int> P;
int sx, sy;

char _map[1000][1001];
int H, W;
char N;
char n = '1';

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

void init(){
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++)d[i][j] = INF;
}

int bfs(){
  int ans = 0;
  queue<P> que;
  init();
  que.push(P(sx, sy));
  d[sx][sy] = 0;

  while(que.size()){
    P p = que.front(); que.pop();
    if(_map[p.first][p.second] == n){
      if(n == N){
        ans += d[p.first][p.second];
        break;
      }else{
        ans += d[p.first][p.second];
        init();
        queue<P> empty;
        swap(que, empty);
        sx = p.first; sy = p.second;
        d[sx][sy] = 0;
        n++;
      }
    }
    for(int i = 0; i < 4; i++){
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if(0 <= nx && nx < H && 0 <= ny && ny < W && _map[nx][ny] != 'X' && d[nx][ny] == INF){
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return ans;
}

void solve(){
  int res = bfs();
  cout << res << endl;
}

int main(){
  cin >> H >> W >> N;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> _map[i][j];
      if(_map[i][j] == 'S'){
        sx = i; sy = j;
      }
    }
  }
  solve();
}

Measured memory_bytes: 6104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> points(m);
    for (int i=0; i < m; i++){
        int l_i;
        cin >> l_i; 
        points[i] = l_i;
    }
    sort(points.begin(), points.end());

    vector<int> pt_diff(m-1);
    for (int i=0; i < m-1; i++){
        pt_diff[i] = points[i+1] - points[i];
    }
    int output = 0;
    if ( m <= n){
        output = 0;
    }else if (m>1){
        sort(pt_diff.begin(), pt_diff.end());
        for (int i = 0; i < pt_diff.size()-n+1 ; i++){
            output = output + pt_diff[i];
        }
    } else {
        output = accumulate(pt_diff.begin(), pt_diff.end(), 0);
    }

    //cout << "get" << endl;


    cout << output << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long W = scn.nextLong(), H = scn.nextLong();
		long x = scn.nextLong(), y = scn.nextLong();
		double ans = (double)(W*H)/2;
		System.out.println(ans + " " + ((2*x==W && 2*y == H)?1:0));
	}

}


Measured memory_bytes: 21332
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (p > b) {
            c3++;
        } else if (p > a) {
            c2++;
        } else {
            c1++;
        }
    }

    int ans = c1;
    if (c2 < ans) {
        ans = c2;
    }
    if (c3 < ans) {
        ans = c3;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
x = S[0]
for i in range(1, n):
    j, k = 0, 0
    tmp = ''
    while j < len(x) and k < len(S[i]):
        if x[j] == S[i][k]:
            tmp += x[j]
            j += 1
            k += 1
        else:
            if x[j] < S[i][k]:
                j += 1
            else:
                k += 1
    x = tmp
print(x)


Measured memory_bytes: 9200
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int r[ 7 ] = { 0 };
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    while ( n-- )
    {
      int d;
      scanf ( "%d", &d );

      r[ 0 ] += !!(            d < 10 );
      r[ 1 ] += !!( d >= 10 && d < 20 );
      r[ 2 ] += !!( d >= 20 && d < 30 );
      r[ 3 ] += !!( d >= 30 && d < 40 );
      r[ 4 ] += !!( d >= 40 && d < 50 );
      r[ 5 ] += !!( d >= 50 && d < 60 );
      r[ 6 ] += !!( d >= 60 );
    }

    printf ( "%d\n%d\n%d\n%d\n%d\n%d\n%d\n"
           , r[ 0 ], r[ 1 ], r[ 2 ], r[ 3 ]
           , r[ 4 ], r[ 5 ], r[ 6 ] );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(),v.end()
#define watch(x) cout<<(#x)<<" = "<<x<<endl
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
#if __cplusplus >= 201402L
template<typename T>
vector<T> create(size_t n) {
	return vector<T>(n);
}
template<typename T, typename ... Args>
auto create(size_t n, Args ... args) {
	return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef EZZAT
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
	run();
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (auto &it : v)
		cin >> it;
	for (int i = k; i < n; i++) {
		if (v[i] <= v[i - k])
			cout << "No\n";
		else
			cout << "Yes\n";
	}
}


Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
void solve()
{
    ll n,m;
    cin>>n>>m;
    ll a[m];
    for(int i=0;i<m;i++) cin>>a[i];
    sort(a,a+m);
    vector<ll>vb;
    ll ans=0;
    if(n<m)
    {
        for(int i=0;i<m-1;i++)
            vb.push_back(a[i+1]-a[i]);
        sort(vb.begin(),vb.end());
        for(int i=0;i<m-n;i++)
            ans+=vb[i];
    }
    cout<<ans<<endl;
}
int main()
{
    Imposter

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 4928
use std::io::*;
use std::collections::HashMap;

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

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

fn main() {
    let v = read_vec::<usize>();
    let (n,k) = (v[0],v[1]);
    let w = read_vec::<usize>();
    let mut m: HashMap<usize,usize> = HashMap::new();
    for a in w {
        if let Some(x) = m.get_mut(&a) {
            *x += 1;
            continue;
        }
        m.insert(a,1);
    }
    let mut val: Vec<_> = m.values().map(|x| *x).collect();
    let mut ans = 0;
    let l = val.len();
    if l > k {
        val.sort();
        ans = val[0..l-k].iter().sum();
    }
    println!("{}",ans);
}


Measured memory_bytes: 17872
N,K = map(int,input().split())
sunukes = [False for i in range(N)] #true→持ってる

for i in range(K):
    d = int(input())
    A = [int(i) for i in input().split()]
    for j in A:
        sunukes[j-1] = True
    
ans = 0
for i in sunukes:
    if not i:
        ans += 1
print(ans)

Measured memory_bytes: 9216