akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	n, k := readInt(), readInt()
	h := make([]int, n)
	for i := range h {
		h[i] = readInt()
	}
	sort.Ints(h)

	fmt.Println(sum(h[:max(0, n-k)]))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 5376
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef pair<int, pii > piii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int H, W, N;
string s, t;
int sx, sy;

signed main(){
    cin >> H >> W >> N >> sx >> sy;
    cin >> s;
    cin >> t;

    bool ans = false;

    int sxt = sx, syt = sy;
    for(int i = 0; i < N; i++){
        if(s[i] == 'R'){
            syt++;
        }
        if(syt > W){
            ans = true;
            //printf("R\n");
        }
        if(t[i] == 'L' && syt > 1){
            syt--;
        }
    }
    

    syt = sy;

    for(int i = 0; i < N; i++){
        if(s[i] == 'L'){
            syt--;
        }
        if(syt <= 0){
            ans = true;
        //printf("L\n");
        }
        if(t[i] == 'R' && syt < W){
            syt++;
        }
    }
    
    
    for(int i = 0; i < N; i++){
        if(s[i] == 'D'){
            sxt++;
        }
        if(sxt > H){
            ans = true;
        //printf("D\n");
        }
        if(t[i] == 'U' && sxt > 1){
            sxt--;
        }
    }
    

    sxt = sx;

    for(int i = 0; i < N; i++){
        if(s[i] == 'U'){
            sxt--;
        }
        if(sxt <= 0){
            ans = true;
        //printf("U\n");
        }
        if(t[i] == 'D' && sxt < H){
            sxt++;
        }
    }
    

    if(ans)printf("NO\n");
    else printf("YES\n");




    return 0;
}

/*

*/

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

int main(){
  int a,b,k;
  cin >> k >> a >> b;
  for(int i=a ; i<=b ; ++i){
    if(i%k ==0){
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

int n;
int a[120000];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i], --a[i];
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] > i && a[a[i]] == i)
			++ans;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 640
import java.util.Scanner;
 
public class Main {    
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();       
        sc.close();
        for(int i=0;i<=x;i++){
            int ans = i * 2 + (x-i) * 4;
            if(ans == y){
                System.out.println("Yes");
                return;
            }
        }        
        System.out.println("No");
    }

}

Measured memory_bytes: 35744
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,x=map(int,input().split())
    a=list(map(int,input().split()))
    ans=0
    for i in range(N):
        ans+=max(a[i]-x,0)
        a[i]=min(a[i],x)
    for i in range(N-1):
        if a[i]+a[i+1]>x:
            ans+=a[i]+a[i+1]-x
            a[i+1]=x-a[i]
    print(ans)

if __name__ == '__main__':
    main()


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

using ll=long long;
int main(){
    int n;
    cin>>n;
    ll ph,pa,pd,ps;
    vector<ll> h(n),a(n),d(n),s(n);
    cin>>ph>>pa>>pd>>ps;
    for(int i=0;i<n;i++){
        cin>>h[i]>>a[i]>>d[i]>>s[i];
    }
    vector<ll> t(n);
    bool poyo=false;
    for(int i=0;i<n;i++){
        if(d[i]>=pa){
            if(a[i]-pd<=0){
                poyo=true;
                t[i]=1;
            }
            else{
                cout<<-1<<endl;
                return 0;
            }
        }
        else{
            t[i]=h[i]/(pa-d[i])+(int)(h[i]%(pa-d[i])>0);
        }
    }
    vector<int> idx(n);
    iota(idx.begin(),idx.end(),0);
    auto cmp=[&](int lhs,int rhs){return (a[lhs]-pd)*t[rhs]>(a[rhs]-pd)*t[lhs];};
    sort(idx.begin(),idx.end(),cmp);
    ll dmg=0;
    for(int i=0;i<n;i++){
        if(s[i]>ps){
            dmg+=max(a[i]-pd,0LL);
        }
    }
    ll sumt=0;
    for(int i=0;i<n;i++){
        int id=idx[i];
        sumt+=t[id];
        if(sumt-1>=1e9+1 && a[id]-pd>0){
            cout<<-1<<endl;
            return 0;
        }
        dmg+=max(a[id]-pd,0LL)*(sumt-1);
        if(dmg>=ph){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(dmg<ph){
        cout<<dmg<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 4696
#include <stdio.h>

int main(void) {
	int n,i,a,cnt;
	
	scanf("%d",&n);
	
	cnt = 0;
	for(i = 0;i < n;i++) {
		scanf("%d",&a);
		if (a % 2) {
			cnt++;
		}
	}
	
	printf("%s\n", cnt%2 ? "NO" : "YES");
	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <list>

using namespace std;

const int MAX_N=200000,MAX_M=200000;
const int MAX_Q=1000;

int N,M,Q;
int a[MAX_M],q[MAX_Q];

bool stu[MAX_N];

int main(){
	scanf("%d %d %d",&N,&M,&Q);
	for (int i=0;i<M;i++){
		scanf("%d",&a[i]);
	}
	for (int i=0;i<Q;i++){
		scanf("%d",&q[i]);
	}
	list<int> ls;
	list<int>::iterator baton;
	//N??????????´??????????
	for (int i=0;i<N;i++){
		ls.push_back(i);
		stu[i]=true;	//????????????
	}
	//M????????????????????????
	baton=ls.begin();
	for (int i=0;i<M;i++){
		for (int j=0;j<a[i];j++){
			if (a[i]&1){
				//?\???°?????´???
				if (baton==ls.begin()){
					baton=ls.end();
					baton--;
				}
				else{
					baton--;
				}
			}
			else{
				//??¶??°?????´???
				baton++;
				if (baton==ls.end()){
					baton=ls.begin();
				}
			}
		}
		//????????????????????£????????????????????????
		list<int>::iterator del=baton;
		stu[*baton]=false;	//???????????????????????????
		baton++;
		if (baton==ls.end()){
			baton=ls.begin();
		}
		ls.erase(del);
	}
	for (int i=0;i<Q;i++){
		printf("%d\n",stu[q[i]]?1:0);
	}
	return 0;
}

Measured memory_bytes: 8260
#include<stdio.h>
int main(void)
{
  int a,b;
  char str[8];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d",&a,&b);
    
  if((a < 9)&&(b < 9))
  {
    puts("Yay!");
  }else
  {
    puts(":(");
  }
  
  return 0;
}

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

int n;

int main()
{
  while (cin >> n, n) {
    vector<int> v = vector<int>(n);
    for (int i = 0; i < n; i++)
      cin >> v[i];
    sort(v.begin(), v.end());

    int sum = accumulate(v.begin(), v.end(), -(v[0]+v[v.size()-1]));
    cout << (sum / (v.size()-2)) << endl;
  }
  return 0;
}

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

struct edge{int to,dir;};


struct graph{
	int n;
	vector<vector<int>>g;
	vector<bool>used;	
	vector<int>ts;	
	vector<int>pr;

	graph(int _n){
		n=_n;
		g.resize(n);
		used.resize(n,false);
		pr.resize(n,-1);
	};

	void add_edge(int a,int b){
		g[a].push_back(b);
	}
	
	void traverse(int i){
		if(used[i])return;
		used[i]=true;
		for(auto&& w:g[i]){
			traverse(w);
		}
		ts.push_back(i);
	}
	void tsort(){
		for(int i=0;i<n;i++){
			traverse(i);
		}
		reverse(begin(ts),end(ts));
//		for(auto&& w:ts)cerr<<w<<endl;
	}

	

	void set_pr(){
		tsort();
		pr[ts[0]]=-1;
		for(int i=0;i<n;i++){
			for(auto&& w:g[ts[i]])pr[w]=ts[i];
		}
	}

};


int main(){
	int n,m;cin>>n>>m;
	graph gr(n);
	for(int i=0;i<n+m-1;i++){
	   int x,y;cin>>x>>y;x--;y--;
		gr.add_edge(x,y);
	}
	 gr.set_pr();
	for(auto&& w:gr.pr)cout<<w+1<<endl;


}

Measured memory_bytes: 8824
val=0
while 1:
    try:
        a,op,b = input().split()
        a=int(a)
        b=int(b)
        if op=='?': 
            break
        elif op=='+':
            val=a+b
        elif op=='-':
            val=a-b
        elif op=='*':
            val=a*b
        elif op=='/':
            val=a//b
        print(val)
    except EOFError:
        #print("EOFError")
        break

Measured memory_bytes: 7636
#include <iostream>
#include <array>

using namespace std;

int main(){
    int N, M, k, val, sum = 0, ans;

    array<int, 100> p;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> p[i];
        sum += p[i];
    }

    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> k >> val;
        cout << sum + val - p[k - 1] << '\n';
    }
    
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct Monoid {
  using T = int;
  static T op(const T& lhs, const T& rhs) { return min(lhs, rhs); }
  static constexpr T e() { return numeric_limits<int>::max(); }
};

template<class Monoid> struct SegmentTree {
  using T = typename Monoid::T;
  struct Node {
    lint l, r, m;
    T val;
    unique_ptr<Node> cl, cr;
    Node(lint l, lint r) : l(l), r(r), m(l + r >> 1), val(Monoid::e()), cl(nullptr), cr(nullptr) {}
  };

  lint n;
  unique_ptr<Node> root;

  SegmentTree(lint n) : n(n), root(make_unique<Node>(0, n)) {}

  T get(lint l, lint r) { return _get(l, r, root); }

  void set(lint i, const T& a) { _set(i, a, root); }

  T _get(lint l , lint r, const unique_ptr<Node>& v) {
    if (l <= v->l and v->r <= r) return v->val;
    T resl = Monoid::e(), resr = Monoid::e();
    if (l < v->m) {
      if (v->cl == nullptr) v->cl = make_unique<Node>(v->l, v->m);
      resl = _get(l, r, v->cl);
    }
    if (v->m < r) {
      if (v->cr == nullptr) v->cr = make_unique<Node>(v->m, v->r);
      resr = _get(l, r, v->cr);
    }
    return Monoid::op(resl, resr);
  }

  void _set(lint i, const T& a, const unique_ptr<Node>& v) {
    if (v->r - v->l == 1) {
      v->val = a;
      return;
    }
    if (i < v->m) {
      if (v->cl == nullptr) v->cl = make_unique<Node>(v->l, v->m);
      _set(i, a, v->cl);
      v->val = Monoid::op(v->cl->val, v->cr != nullptr ? v->cr->val : Monoid::e());
    } else {
      if (v->cr == nullptr) v->cr = make_unique<Node>(v->m, v->r);
      _set(i, a, v->cr);
      v->val = Monoid::op(v->cl != nullptr ? v->cl->val : Monoid::e(), v->cr->val);
    }
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  SegmentTree<Monoid> st(n);
  for (int i = 0; i < q; ++i) {
    int c, x, y; cin >> c >> x >> y;
    if (!c) st.set(x, y);
    else cout << st.get(x, y + 1) << '\n';
  }
}


Measured memory_bytes: 13404
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 998244353;

string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int res = 0;
    REP(i, 0, n-2) {
        if (s.substr(i, 3) == "ABC") ++res;
    }
    cout << res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define M 1000000007

int32_t main()
{   fast

    int a,b;
    cin>>a>>b;
    int ans=a-2*b;
    if(ans<=0) cout<<0;
    else cout<<ans;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    String S = in.next();
    System.out.println(solve(N, S));
  }

  private static int solve(int N, String S) {
    int ret = 0;
    for (int i = 0; i < 1000; i++) {
      if (can(i, S))
        ret++;
    }
    return ret;
  }

  private static boolean can(int i, String S) {
    String key = String.format("%03d", i);

    int startIndex = 0;
    for (int j = 0; j < 3; j++) {
      int index = S.indexOf(key.charAt(j), startIndex);
      if (index < 0)
        return false;
      startIndex = index + 1;
    }
    return true;
  }
}

Measured memory_bytes: 44372
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
const int MAXN = 1e5+2;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "YES\n"; return 0;}

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a,b,c;
    cin >> a >> b >> c;
    int r = a-b;
    cout << max(0,c-r) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,k;
  cin >> n >> k;
  int x=1;
  rep(i,n) x=min(x*2,x+k);
  pr(x);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
  int n, a;
  scanf("%d %d", &n, &a);
  int min = a & (-a);
  for (int i = 1; i < n; ++i)
  {
    scanf("%d", &a);
    if (min > (a & (-a))) min = (a & (-a));
  }
  int ans = 0;
  while ((min & 1) == 0)
  {
    min >>= 1;
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

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

int max(int a, int b)
{
    return (a > b ? a : b);
}

int main(void)
{
    int n, t, s;
    int a[3001], b[3001];
    int dp[3001];
    int res;
    int i, j;
    
    scanf("%d%d%d", &n, &t, &s);
    
    memset(dp, 0, sizeof(dp));
    
    res = 0;
    
    for (i = 0; i < n; i++){
        scanf("%d%d", &a[i], &b[i]);
        
        for (j = t - b[i]; j >= 0; j--){
            if (!(j < s && s < j + b[i])){
                dp[j + b[i]] = max(dp[j + b[i]], dp[j] + a[i]);
                res = max(dp[j + b[i]], res);
            }
        }
    }
    
    printf("%d\n", res);
    
    return (0);
}

Measured memory_bytes: 0
def m():
    n = int(input())
    S = [str(input()) for _ in range(n)]
    m = 0
    a = 0
    r = 0
    c = 0
    h = 0
    x = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    y = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    z = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
    for i in range(n):
        if S[i][0] == "M":
            m += 1
        elif S[i][0] == "A":
            a += 1
        elif S[i][0] == "R":
            r += 1
        elif S[i][0] == "C":
            c += 1
        elif S[i][0] == "H":
            h += 1
    ans = 0
    d = [m, a, r, c, h]
    for j in range(10):
        ans += d[x[j]] * d[y[j]] * d[z[j]]
    return ans
print(m())


Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
unsigned long long  sumXOR(ll arr[], int n)
{
    unsigned long long  sum = 0;
    for (int i = 0; i < 64; i++)
    {
        //  Count of zeros and ones
        ll zc = 0, oc = 0;

        // Individual sum at each bit position
        unsigned long long  idsum = 0;
        for (int j = 0; j < n; j++)
        {
            if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;
        }

        // calculating individual bit sum
        idsum = ( ((1ll*oc * zc)%MOD) * ((1ll << i)%MOD))%MOD;

        // final sum
        sum += (idsum%MOD);
    }
    return sum%MOD;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;++i) cin>>a[i];
    cout<<sumXOR(a,n);
}


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

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double pi = 3.141592653589793; 
  double x=sqrt(a*a+b*b-2*a*b*cos(2*pi*((h*60+m)/720-m/60)));
  cout << fixed << setprecision(15) << x << endl;
}

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

int main(void){
	string s;
	cin>>s;

	for(int i=0 ; i<s.length() ; i++){
		if(s[i] == 'U' || s[i] == 'D'){
			continue;
		}
		if(i % 2 == 0){
			if(s[i] != 'R'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		if(i % 2 == 1){
			if(s[i] != 'L'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);

const int N = 505;
int step[N][N];
int isAvaliable[N][N];
int p[N*N];
int n;

void init() {
    scanf(I,&n);
    rep (i,n*n) scanf(I,&p[i]);   
    rep (i,n*n) p[i]--;
    rep (i,n) rep (j,n) step[i][j] = min( min(i,n-i-1) , min(j,n-j-1) );
    rep (i,n) rep (j,n) isAvaliable[i][j] = 1;
}

const int Move[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};

void update(int x, int y) {
    rep (b, 4) {
        int nx = x+Move[b][0], ny = y+Move[b][1];
        if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
        if (checkMin(step[nx][ny] , step[x][y] + isAvaliable[x][y])) update(nx, ny);
    }
}

void solve() {
    int res = 0;
    rep (i,n*n) {
        int x=p[i]%n, y=p[i]/n; 
        res += step[x][y];
        isAvaliable[x][y] = 0;
        update(x,y); 
    }
    printf(IN,res);
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


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

int main(){
  string c;
  cin >> c;
  int flag = 1;
  vector<string> p = {"a","i","u","e","o"};
  for(int i=0;i<p.size();i++){
    if (c==p.at(i)){
      flag = 0;
    }
  }
  if (flag==1){
    cout << "consonant" << endl;
  }else{
    cout << "vowel" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
bool vis[1010][1010];
int n,dis1,dis2,tot;
void init(int x){
	int t=0;
	while(x%4==0)t++,x/=4;
	if(x%4==1)
		for(int i=0;i<n*2;i++) 
			for(int j=0;j<n*2;j++)
			vis[i][j]|=(i^j)>>t&1;
	else for(int i=0;i<n*2;i++) 
			for(int j=0;j<n*2;j++)
			vis[i][j]|=i>>t&1;
}
int main(){
	scanf("%d%d%d",&n,&dis1,&dis2);
	init(dis1),init(dis2);
	for(int i=0;i<2*n;i++)
		for(int j=0;j<2*n;j++){
			if(!vis[i][j])printf("%d %d\n",i,j),tot++;
			if(tot==n*n)return 0;
		}
}

Measured memory_bytes: 1408
inputLine = gets.chomp.split(" ")
numSubjects = inputLine[0].to_i
numSubmit = inputLine[1].to_i
wa = Array.new(100000, 0)
ac= Array.new(100000, false)
acnum = 0
wanum = 0
 
for i in 0 .. numSubmit - 1
  inputLine = gets.chomp.split(" ")
  targetSubject = inputLine[0].to_i
  result = inputLine[1]
  if ac[targetSubject] then
    next
  end
  if result == "AC" then
    ac[targetSubject] = true
    acnum += 1
    wanum += wa[targetSubject]
  elsif result == "WA" then
    wa[targetSubject] += 1
  end
end
printf("%d %d\n",acnum, wanum)

Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], n, t;
int main() {
	scanf("%d%d", &n, &t);
	for(int i = 1; i <= n; ++ i)
		scanf("%d", a + i);
	int m = 0, now = -1, cnt = 0;
	for(int i = n; i; -- i) {
		m = max(m, a[i]);
		int dif = m - a[i];
		// cerr << i <<" " << dif
		if(dif > now)
			now = dif, cnt = 1;
		else if(dif == now)
			++ cnt;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 4064
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> a_max(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  a_max = a;
  sort(a_max.rbegin(), a_max.rend());
  for (int i=0; i<n; i++) {
    if(a[i] == a_max[0])
      cout << a_max[1] << endl;
    else
      cout << a_max[0] << endl;
  }
}

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

//ループ関連
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define for(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define ford(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//定数
#define PI 3.14159265359
#define MOD 1000000007
#define INF 1000000000000
 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  double R; cin >> R;
  cout << R * 2 * PI;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll a[n+1]={};
  for(int i=1;i<n+1;i++)cin >> a[i];
  ll b[n+1]={};//答え
  vector<ll> d;

  b[n]=a[n];
  if(b[n]==1)d.push_back(n);
  for(int i=n-1;i>0;i--){
    ll c=0;
    ll k=1;
    while(i*k<=n){
      c+=b[i*k];
      k++;
    }
    b[i]=abs(c%2-a[i]);
    if(b[i]!=0)d.push_back(i);
  }

  if(d.empty())cout << 0 << endl;
  else{
    cout << d.size() << endl;
    for(int i=0;i<d.size();i++)cout << d[i] <<" " ;
  }

}

Measured memory_bytes: 7288
#include <cstdlib>
#include <iostream>
#include <unordered_map>


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

  int x, y;
  std::cin >> x >> y;

  std::unordered_map<int, int> groupMap{
    {1, 0},
    {3, 0},
    {5, 0},
    {7, 0},
    {8, 0},
    {10, 0},
    {12, 0},
    {4, 1},
    {6, 1},
    {9, 1},
    {11, 1},
    {2, 2},
  };
  std::cout << (groupMap[x] == groupMap[y] ? "Yes" : "No") << std::endl;

  return EXIT_SUCCESS;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;

vector<int> v;

int f[3][3];
int main(){
    int m[3][3];
    for(int i=0; i<3; ++i){
        for(int j=0; j<3; j++){
            cin >> m[i][j];
        }
    }
    
    int n,a ;
    cin >> n;
    while(n--){
        cin >> a;
        for(int i=0; i<3; ++i){
            for(int j=0; j<3; j++){
                if(a == m[i][j]){
                    f[i][j]=1;
                }
            }
        }
    }
    bool ans=false;
    for(int i=0; i<3; ++i){
        if(f[i][0] and f[i][1] and f[i][2]) ans=true;
        if(f[0][i] and f[1][i] and f[2][i]) ans=true;
    }
    if(f[0][0] and f[1][1] and f[2][2]) ans=true;

    if(f[0][2] and f[1][1] and f[2][0]) ans=true;

    if(ans) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

int a, b, x;

int gcd(int m, int n){
	if (!m || !n) return 0;
	while (m != n){
		if (m > n) m -= n;
		else n -= m;
	}
	return m;
}

int lcm(int cx, int cy)
{
	if (!cx || !cy) return 0;
	return cx*cy / gcd(cx, cy);
}

int main(){
	cin >> a;
	cin >> x;
	REP(i, a - 1)
	{
		cin >> b;
		x = lcm(x, b);
	}
	cout << x << endl;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] price = new int[n];
        for(int i = 0; i < n; i++)
            price[i] = sc.nextInt();
        Arrays.sort(price);
        int sum = 0;
        for(int i = 0; i < k; i++)
            sum += price[i];
        System.out.println(sum);
    }
}

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

using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long int
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define L(x) ('a'<=x && x<='z')
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  200*1000 + 1;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
const double epsilon = 1e-9; 
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}

 int32_t main(){
    IOS;
 
   int t;
   //cin>>t;
       t=1;
   while(t--){

      int n;
      cin>>n;

     int ans=binpow(10,n);

     ans= (ans%mod - (2*binpow(9,n))%mod + mod)%mod;

     ans = ( ans%mod + binpow(8,n)%mod)%mod;

     cout<<ans<<endl;

    
   }
}
 

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main()
{
    int mm = 9999;
    int p[5];
    for( int i=0; i<5; ++i ) {
        cin >> p[i];
    }

    for( int i=0; i<3; ++i )
        for( int j=3; j<5; ++j )
            mm = min( mm, p[i] + p[j] - 50 );

    cout << mm << endl;
}

Measured memory_bytes: 1160
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0 for i in[0]*n];d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
 L=[];y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if not(l[x][a[x]]-1!=i or x in L or i in L):
    a[i]+=1;a[x]+=1;L+=[i,x];y=1
 d*=y
print([k//2,d-1][d<9999])

Measured memory_bytes: 54236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a == b && b == c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#define mod 1000000007
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define srep(i,s,t) for (ll i = s; i < t; i++)
#define drep(i,n) for(ll i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;


int main()
{
    ll k;
    cin >> k;
    ll ans=0;
    vector<ll> a(k);
    rep(i,k){
        cin>>a[i];
        if(i%2==0){
            if(a[i]%2!=0){
                ans++;
            }
        }
    }
    cout<< ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2000000+234;
int n,m,x,c[50],a[50][50],mini=INT_MAX;
int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
		for(int j=0;j<m;j++)scanf("%d",&a[i][j]);
	}
	for(int i=0;i<(1<<n);i++){//枚举所有可能的方案，每一个i对应一个方案
		int sum[50],cost=0;
		memset(sum,0,sizeof(sum));
		for(int j=0;j<n;j++)
			if(i&(1<<j)){
				for(int k=0;k<m;k++)sum[k]+=a[j][k];
				cost+=c[j];
			}//i的第j位是1，在i的方案中，包含j这本书
//		cout<<i<<":"<<cost;
//		for(int k=0;k<m;k++)cout<<" "<<sum[k];
//		cout<<endl;
		bool f=1;
		for(int k=0;k<m;k++)
			if(sum[k]<x){f=0;break;}
		if(f==1)mini=min(mini,cost);
	}
	if(mini==INT_MAX)printf("%d",-1);
	else printf("%d",mini);
	return 0;
}

Measured memory_bytes: 3700
use std::str::FromStr;
use std::fmt::Debug;

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

fn main() {
    let _: Vec<i32> = read_line();
    let hs: Vec<i32> = read_line();
    let mut h: i32 = hs[0] - 1;
    let mut valid: bool = true;

    for i in 1..hs.len() {
        if h > hs[i] { valid = false; };
        if h == hs[i] { continue; };
        h = hs[i] - 1;
    };

    println!("{}", if valid { "Yes" } else { "No" });
}

Measured memory_bytes: 6396
#include <stdio.h>

int main(){

  int n,sum,count,i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    count=0;
    for(i=1;i<n-1;i++){
      sum=i;
      for(j=i+1;j<n;j++){
	sum += j;
	if(sum==n)count++;
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    A = [list(reversed(a)) for a in A]

    s1 = set()
    s2 = set()
    for i in range(1, N+1):
        if A[i-1]:
            d = A[i-1][-1]
            n = (min(i, d), max(i, d))
            if n not in s1:
                s1.add(n)
            else:
                s2.add(n)
                s1.remove(n)
        
    while True:
        c = 0
        dell = []
        adding = []
        for k in s2:
            a, b = k
            A[a-1].pop()
            if A[a-1]:
                d = A[a-1][-1]
                n = (min(a, d), max(a, d))
                adding.append(n)
            A[b-1].pop()
            if A[b-1]:
                d = A[b-1][-1]
                n = (min(b, d), max(b, d))
                adding.append(n)
            dell.append(k)
            c += 1

        for k in dell:
            s2.remove(k)
        for k in adding:
            if k in s1:
                s2.add(k)
                s1.remove(k)
            else:
                s1.add(k)

        if c == 0:
            break
        else:
            ans += 1


    for a in A:
        if a:
            return -1
    return ans


def main():
    N = read_int()
    A = [read_int_n() for _ in range(N)]
    print(slv(N, A))

    # N = 1000
    # A = []

    # while True:
    #     for i in range(1, N+1):
    #         t = list(range(1, N+1))
    #         t.remove(i)
    #         random.shuffle(t)
    #         A.append(t)
    #     print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 96088
#include "bits/stdc++.h"
using namespace std;
int main() {
	long N; cin >> N;
	vector<long>A(N);
	for (int i = 0; i < N; i++)cin >> A.at(i);
	sort(A.begin(), A.end(), greater<int>());
	int odd = 0;
	for (int i = 0; i < N; i++) {
		if (A.at(i) % 2 != 0) odd++;
	}
	if (odd % 2 != 0) odd--;
	long ans = 0;
	for (int i = 0; i < N; i++) {
		if (A.at(i) % 2 != 0) odd--;
		else ans += A.at(i);
		if (odd < 0) ans += 0;
		else if (odd >= 0 &&A.at(i) % 2!=0) ans += A.at(i);
	}
	cout << ans / 2 << endl;
}


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

int main(){
  long long a,b,c,x,y,i,ans=0;
  cin>>a>>b>>c>>x>>y;
  
  if(c*2>=a+b){
    cout<<a*x+b*y<<endl;
    return 0;
  }else{
    if(x>y){
      ans+=c*2*y;
      if((x-y)*a<=2*(x-y)*c){
        ans+=(x-y)*a;
      }else{
        ans+=(x-y)*2*c;
      }
    }else if(x<y){
      ans+=c*2*x;
      if((y-x)*b<=2*(y-x)*c){
        ans+=(y-x)*b;
      }else{
        ans+=(y-x)*2*c;
      }
    }else{
      cout<<c*2*x<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vi b;
    loop(i, 1, n) b.pb(a[i] - a[i - 1]);
    cout << *min_element(all(b)) << endl;
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

vector<string> ans;
int N;

void dfs(string S, int n) {
  if (n == N) {
    ans.pb(S);
    return;
  }

  set<char> s;
  for (char c : S) {
    s.insert(c);
  }

  s.insert(*(s.rbegin()) + 1);
  for (char c : s) {
    string temp = S;
    temp.pb(c);
    dfs(temp, n + 1);
  }
}

signed main() {
  cin >> N;

  dfs("a", 1);
  sort(all(ans));

  rep(i, len(ans)) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 9716
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: u64 = read();
    let k: u64 = read();
    let mut ret: u64 = 0;

    for i in k..(n + 2) {
        let min = i * (i + 1) / 2;
        let max = (n + 1) * (n + 2) / 2 - (n + 1 - i) * (n + 2 - i) / 2;
        ret = (ret + max - min + 1) % 1000000007;
    }
    println!("{}", ret);
}


Measured memory_bytes: 2108
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
 
using namespace std;
 
using ll = long long int; 
 
void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;
 
    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}
 
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}
 
ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}
 
const int MAX = 50;
const int MOD = 1000000007;
 
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(void){
 
  int n, m;
  cin>>n>>m;

  vector<vector<int>> s(m);

  for(int i=0;i<m;i++){
    int k;
    cin>>k;

    for(int j=0;j<k;j++){
      int x;
      cin>>x;
      s[i].push_back(x);
    }
  }
  vector<int> p(m);
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    p[i] = x;
  }

  int piv;
  int count = 0;

  for(int bit=0;bit<(1<<n);++bit){ //onになるスイッチの集合
    piv = 0;
      for(int i=0;i<m;i++){ //各電球
        int ans = 0;
        for(int j=0;j<s[i].size();j++){
          if(bit & (1<<(s[i][j]-1))) ans++;
        }
        //cout<<ans<<endl;
        if(ans%2==p[i]) piv++;
      }
      if(piv==m) count++;
  }

  cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
A = list(map(int, input().split()))
# 2本以上ある棒, 4本以上を選び出してsort, 大きいものから選ぶ
A = sorted(A)
c = collections.Counter(A)
c_2 = sorted(c.items(), key=lambda x:x[0], reverse=True)
count = 0
for i in range(n):
    if c_2[i][1] >=4 and count==0:
        ans = c_2[i][0] **2
        count+=2
        break
    elif c_2[i][1]>=2:
        if count==0:
            ans = c_2[i][0]
            count+=1
        elif count==1:
            ans *= c_2[i][0]
            count+=1
            break
if count!=2:
    print(0)
else:
    print(ans)

Measured memory_bytes: 22308
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, q = map(int, readline().rstrip().split())
    s = readline().rstrip()
    LRList = [list(map(int, readline().rstrip().split())) for _ in range(q)]
    sumAC = 0
    ACList = [0] * (n)
    for i in range(1, n):
        if s[i - 1: i + 1] == 'AC':
            sumAC += 1
        ACList[i] = sumAC
    for j in range(q):
        l, r = LRList[j][0], LRList[j][1]
        print(ACList[r-1] - ACList[l-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 29860
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 998244353;

int main()
{
    int n, s;
    cin >> n >> s;
    VI dp(3030, 0);
    dp[0] = 1;
    rep(i, n)
    {
        int a;
        cin >> a;
        auto next = dp;
        rep(j, 3030)
        {
            next[j] *= 2;
            next[j] %= MOD;
            if (j - a >= 0)
            {
                next[j] += dp[j - a];
            }
            next[j] %= MOD;
        }
        dp = next;
    }
    cout << dp[s] << endl;
}

Measured memory_bytes: 3616