akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
	int key;
	struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
/*↓alds18aから付け足した部分*/
Node * find(Node *u, int k){
	while(u!=NIL&&k!=u->key){
		if(k<u->key){
			u=u->left;
		}else{
			u=u->right;
		}
	}
	return u;
}
/*↑alds18aから付け足した部分*/

/*↓alds18bから付け足した部分*/
Node * treeMinimum(Node *x) {
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node * treeSuccessor(Node *x) {
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  // yの子xを決める
  if(y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL) {
    x->parent = y->parent;
  }

  if(y->parent == NIL) {
    root = x;
  } else {
    if(y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z) {
    z->key = y->key;
  }
}

/*↑alds18bから付け足した部分*/

int main(void) {
	int n, i, x;
	char com[16];
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		scanf("%s",com);
		/*↓alds18aから付け足した部分*/
		if(!strcmp(com,"find")){
			scanf("%d",&x);
			Node *t=find(root,x);
			if(t!=NIL){
				printf("yes\n");
			}else{
				printf("no\n");
			}
			/*↑alds18aから付け足した部分*/
		}else if(!strcmp(com,"insert")) {
			scanf("%d",&x);
			insert(x);
		} else if(!strcmp(com,"print")) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
			/*↓alds18bから付け足した部分*/
		}else if(!strcmp(com,"delete")){
			scanf("%d",&x);
			treeDelete(find(root,x));
		}
		/*↑alds18bから付け足した部分*/
	}

	return 0;
}


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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

int main()
{
	int n, l;
	sii(n, l);
	int sum = 0;
	for(int i = 0; i < n; i++)
		sum += l+i;

	int ans = INT_MAX;
	int ans2;
	for(int i = 0; i < n; i++)
	{
		int nuevo = sum - (l+i);
		if(abs(nuevo - sum) < ans)
		{
			ans = abs(nuevo - sum);
			ans2 = nuevo;
		}
	}
	printf("%d\n", ans2);

    return 0;
}


Measured memory_bytes: 256
# 写経
n = int(input())
lst_r = [list(map(int, input().split())) for _ in range(n)]
lst_b = [list(map(int, input().split())) for _ in range(n)]
lst_r.sort(key=lambda x:-x[1])
lst_b.sort()


ans = 0
for b in lst_b:
    for r in lst_r:
        if r[0] < b[0] and r[1] < b[1]:
            ans += 1
            lst_r.remove(r)
            break


print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

const int mod = 1000000007;
ll R,R2,modash;
int logR;
ll MR(ll x){
    ll ret = (x + ((x*modash)&(R-1ll))*mod)>>(logR);
    return (ret>=mod ? ret-mod : ret);
}
int get_mod(ll x){return (int)MR(MR(x)*R2);}
void init(){
    R=1ll;logR=0;modash=0;
    while(R<mod){R<<=1;logR++;}
    R2=R*R%mod;
    int t=0,r=R,i=1;
    while(r>1){
        if((t&1)==0){t+=mod;modash+=i;}
        t>>=1;r>>=1;i<<=1;
    }
}

vector<vl> mul(vector<vl> a, vector<vl> b){
  int n = a.size();
  vector<vl> ret(n,vl(n,0));
  REP(k,n)REP(i,n)REP(j,n){
    ret[i][j] += a[i][k]*b[k][j]%mod;
    ret[i][j] %= mod;
    // ret[i][j] = get_mod(ret[i][j] + get_mod(a[i][k])*get_mod(b[k][j]));
  }
  return ret;
}

int main(){
  int n,k,c,t;
  scanf("%d%d%d%d",&n,&k,&c,&t);
  // ????§???????
  // 0?§???????1?§????...4?§????????£??????§??\?????????????????°t?????§?????¨?????????
  vector<vl> mat(5*n,vl(5*n,0));
  // ??????????§?
  REP(i,4){
    REP(j,n) mat[i*n+j][(i+1)*n+j] += 1;
  }
  // ?????????????§?
  REP(_,k){
    int a,b,tm;
    scanf("%d%d%d",&a,&b,&tm);
    // --a; --b;
    --tm;
    REP(i,n){
      int from;
      if(i<b) from = i+a-1;
      else if(i<b+a-1) from = i-b;
      else from = i;
      int to = i;
      mat[tm*n+to][from] += 1;
    }
  }
  // REP(po,5*n){
  //   DEBUG_VEC(mat[po]);
  // }
  // cout<<endl;
  // init();
  // ?´????
  vector<vl> ans(5*n,vl(5*n,0));
  REP(i,5*n) ans[i][i]=1;
  while(t){
    if(t&1) ans = mul(ans,mat);
    mat = mul(mat,mat);
    t>>=1;
  }
  // DEBUG
  // REP(po,5*n){
  //   DEBUG_VEC(ans[po]);
  // }
  cout<<ans[0][c-1]<<endl;
  return 0;
}

Measured memory_bytes: 2712
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if (n%10==9) cout<<"Y"<<"e"<<"s"<<endl;
	else if (n/10%10==9) cout<<"Y"<<"e"<<"s"<<endl;
	else cout<<"N"<<"o"<<endl;
	return(0);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==1)a=14;
  if(b==1)b=14;
  if(a>b)cout<<"Alice"<<endl;
  else if(a<b)cout<<"Bob"<<endl;
  else cout<<"Draw"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  string s; cin >> s;
  cout << s.front() << s.length() - 2 << s.back() << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		PriorityQueue<Double> pq = new PriorityQueue<>(Collections.reverseOrder());
		for(int i = 0; i < N; i++)
			pq.offer(sc.nextDouble());
		for(int i = 0; i < M; i++)
			pq.offer(pq.poll()/2);
		long ans = 0;
		int size = pq.size();
		for(int i = 0; i < size; i++)
			ans += pq.poll();
		System.out.println(ans);

	}

}

Measured memory_bytes: 96968
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
n = int(input())
A = [int(x) for x in range(1,n+1)]
B = [0]*n

for i in range(n):
    while A[i] % 2 == 0:
        A[i] = A[i]//2
        B[i] += 1
        
ind = B.index(max(B))
tmp = [int(x) for x in range(1,n+1)]
print(tmp[ind])

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll ans = 0;
    while (x >= 5)
    {
        if (x >= 500)
        {
            ans += 1000;
            x -= 500;
        }
        else if (x >= 5)
        {
            ans += 5;
            x -= 5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main() {
  bool ans = true;
  int a[5];
  int k;
  fr(i,5){
    cin >> a[i];
  }
  sort(a, a + 5, greater<int>());
  cin >> k;
  if(abs(a[0]-a[4])>k) ans = false;
  if(ans)cout << "Yay!" << endl;
  else{cout << ":(" << endl;}
}

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

const int INF = 0x3f3f3f3f, MOD = 1e9+7, MAX_N = 105, MAX_K = 100005;
int N, K;
int a[MAX_N];
vector<int> dp1(MAX_K), dp2(MAX_K);

void solve()
{
	ll tot = accumulate(a, a+N, 0LL);
	if(K>tot) cout << 0 << endl;
	else{
		dp1[0]=1;
		for(int i=0;i<N;++i){
		    ll sum = 0;
			for(int j=0;j<=K;++j){
			    sum = (sum + dp1[j])%MOD;
			    if(j-a[i]>=1){ 
			        sum = (sum-dp1[j-a[i]-1])%MOD;
			        sum = (sum + MOD)%MOD;
			    }
			    dp2[j]=sum;
			}
			swap(dp1, dp2);
		}
		int ans = dp1[K];
		while(ans < 0) ans += MOD;
		cout << ans << endl;
	}
}
int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i)cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 1152
N=input()
D=list(map(int,input().split()))
M=max(D)
l=[0]*(M+1)
for i in D:
    l[i]+=1
if l[0]==1 and D[0]==0:
    a=1
    for i in range(2,M+1):
        a*=pow(l[i-1],l[i],998244353)
    a%=998244353
    print(a)
else:
    print(0)

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL K,A,B;
  cin>>K>>A>>B;
  FOR(i,A,B+1){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N;
  cin >> N;

  vector<int> A(N);
  vector<bool> visited(N);
  for (int &a : A) {
    cin >> a;
  }

  int x = 0;
  int ans = 0;
  while (!visited[x]) {
    if (x == 1) {
      cout << ans << endl;
      return;
    }

    visited[x] = true;
    x = A[x] - 1;
    ans++;
  }
  cout << -1 << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 1152
/* 
 * Project: AtCoder Beginners Contest 138 C - Alchemist
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/05
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;

uint32_t n;
vector<uint32_t> v;

void solve() {


    sort(v.begin(), v.end());
    double ave = (v[0]+v[1])/2.0;
    for (int i=2;i<n;i++) {
        ave = (ave + v[i])/2.0;
    }

    printf("%lf\n", ave);
}

int main() {

    scanf("%d", &n);
    v.resize(n);
    for (int i=0;i<n;i++) {
        scanf("%d", &v[i]);
    }

    solve();
}

Measured memory_bytes: 3232
from itertools import accumulate
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
a = list(map(int, input().split()))
cum = list(accumulate([0, 0] + a))
left = [0] * (N+2)
for i in range(1, N+1):
    left[i] = left[i-1]
    if a[i-1] > 0:
        left[i] += a[i-1]
right = [0] * (N+2)
for i in range(1, N+1)[::-1]:
    right[i] = right[i+1]
    if a[i-1] > 0:
        right[i] += a[i-1]
ans = 0
for i in range(1, N-K+2):
    tmp = left[i-1] + right[i+K]
    if cum[i+K] - cum[i] > 0:
        tmp += cum[i+K] - cum[i]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 67564
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	string s; cin >> s;
	int k; cin >> k;
	set<string> brute;
	for (int c = 'a'; c <= 'z'; ++c) {
		for (int i = 0; i < (int)s.size(); ++i) {
			if (s[i] == c) {
				string temp = "";
				for (int j = i; j < min((int)s.size(), i + 5); ++j) {
					temp += s[j];
					brute.insert(temp);
				}
			}
		}
	}
	assert(brute.size() >= k);
	string ans = "";
	for (auto st : brute) {
		--k;
		if (k == 0) {
			ans = st;
			break;
		}
		// cout << st << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1664
n,m=[int(j) for j in input().split()]
s=input()[::-1]
l=[]
for i in range(n+1):
    if s[i]=="0":
        l.append(i)
import bisect
ans=[]
c=0
while True:
    if c+m>=n:
        ans.append(n-c)
        break
    p=bisect.bisect_right(l,c+m)-1
    ans.append(l[p]-c)
    if l[p]-c==0:
        print(-1)
        exit()
    c=l[p]
    if c==n:
        break
print(*ans[::-1])




Measured memory_bytes: 10248
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] P = new int[N];
        for (int i = 0; i < N; i++) P[i] = sc.nextInt();

        int[] sortedFrom = new int[N];
        int sol = 0;

        for (int i = 1; i < N; i++) {
            sortedFrom[i] = P[i] >= P[i - 1] ? sortedFrom[i - 1] : i;
            if (i - sortedFrom[i] >= K - 1) sol = 1;
        }

        SortedSet<Integer> window = new TreeSet<>();
        for (int i = 0; i < K; i++) window.add(P[i]);

        for (int i = 0; i + K - 1 < N; i++) {
            if (i > 0) {
                window.remove(P[i - 1]);
                window.add(P[i + K - 1]);
            }
            if (sortedFrom[i + K - 1] <= i) continue;
            if (i + K == N) {
                sol++;
                break;
            }
            if (P[i] != window.first() || P[i + K] < window.last()) sol++;
        }
        System.out.println(sol);
    }
}


Measured memory_bytes: 96784
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {   
    int n, k;
    cin >> n >> k;
    int ans = k * pow(k - 1, n - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	cin >>n;
	vector<pair<pair<string,int>,int>>ans(n);
	rep(i,n){
		cin>>ans[i].F.F>>ans[i].F.S;
		ans[i].F.S=100-ans[i].F.S;
		ans[i].S=i+1;
	}
	sort(all(ans));
	for(int i=0;i<n;i++){
		cout<<ans[i].S<<endl;
	}
	//cout<<ans<<endl;
}

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

int main() {
  string s; cin >> s;
  int ans1=0; int ans2=0;
  rep(i,s.size()){
    if(i%2 == 0){
      if(s[i] == '0') ans1++;
      else ans2++;
    }
    else{
      if(s[i] == '1') ans1++;
      else ans2++;
    }
  }
  
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();

		if (x == 1 && y == 1) {
			System.out.println(1000000);
		} else {
			int ans = 0;
			if (x == 1) ans += 300000;
			if (x == 2) ans += 200000;
			if (x == 3) ans += 100000;
			if (y == 1) ans += 300000;
			if (y == 2) ans += 200000;
			if (y == 3) ans += 100000;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23636
#include<iostream>

using namespace std;


int main()
{
	int n, q, S[100000], T[50000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	for (int i = 0; i < q; i++)
		cin >> T[i];
	int c = 0, k;
	for (int i = 0; i < q; i++)
	{
		k = T[i];
		int left = 0, right = n - 1, mid = (left + right) / 2;
		while (left <= right)
		{
			if (S[mid] == k)
			{
				c++;
				break;
			}
			else if (k > S[mid])
				left = mid + 1;
			else 
				right = mid - 1;
			mid = (left + right) / 2;
		}
	}
	cout << c << endl;
	return 0;
}



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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1;
    int b = y2 - y1;

    int x3 = x2 - b;
    int y3 = y2 + a;
    int x4 = x1 - b;
    int y4 = y1 + a;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();

        switch (S) {
            case "ABC":
                System.out.println("ARC");
                break;
            case "ARC":
                System.out.println("ABC");
                break;
        }
    }
}

Measured memory_bytes: 35680
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Storable         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [h, w] <- map read.words <$> getLine :: IO [Int]
    B.PS p 0 l <- C.filter (\c -> c == '#' || c == '.') <$> C.getContents
    let mat = U.unsafeFromForeignPtr0 p l
    print $ solve h w mat

solve :: Int -> Int -> U.Vector Word8 -> Int
solve h w mat = subtract 3 . U.maximum $ U.zipWith (+) lr ud
  where
    trans :: U.Vector Int -> U.Vector Int
    trans m = U.unsafeBackpermute m $ U.generate (h * w) $ \ij ->
        let (i, j) = quotRem ij w
        in j * h + i

    lr :: U.Vector Int
    lr = U.concatMap (\i ->
        let row = U.unsafeSlice (i * w) w mat
        in U.zipWith (+)
            (U.postscanl' (\acc c -> if c == B.c2w '#' then 0 else acc + 1) 0 row)
            (U.postscanr' (\c acc -> if c == B.c2w '#' then 0 else acc + 1) 0 row)
        )
        $ U.generate h id

    ud :: U.Vector Int
    ud = trans
        . U.concatMap (\j ->
            let column = U.map (U.unsafeIndex mat) $ U.iterateN h (+w) j
            in U.zipWith (+)
                (U.postscanl' (\acc c -> if c == B.c2w '#' then 0 else acc + 1) 0 column)
                (U.postscanr' (\c acc -> if c == B.c2w '#' then 0 else acc + 1) 0 column)
        )
        $ U.generate w id


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
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;
}

// 2 dimentional vector
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]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n ,x;
    string s;
    cin>>n>>x;

    Yes(n*500>=x)
    return  0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        double[] v = new double[N];
        for(int i = 0; i < N; i++){
            v[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(v);
        for(int i = 0 ; i < N-1; i++){
            v[1] = (v[0] + v[1]) / 2;
            v[0] = 1001;
            Arrays.sort(v);
        }
        System.out.println(v[0]);
    }
}

Measured memory_bytes: 22612
import numpy as np

N, M = map(int, input().split())

dtype = [('start', int), ('end', int)]
req = np.empty([M], dtype=dtype)

for i in range(M):
    a, b = map(int, input().split())
    req[i] = (a-1, b-1)

req.sort(order=['end'])

cutList = []

def isConnected(start, end):
    for i in cutList:
        if start <= i and i < end:
            return False
    return True

ans = 0

for i in range(M):
    if isConnected(req[i][0], req[i][1]):
        cutList.append(req[i][1]-1)
        ans += 1

print(ans)


Measured memory_bytes: 16080
S = list(input())[::-1]
L,i = len(S),0
words = [list(word) for word in ['maerd', 'esare', 'remaerd', 'resare'] ]

while i < L-7:
    if S[i:i+5] in words[:2]:  i += 5
    elif S[i:i+6] == words[3]: i += 6
    elif S[i:i+7] == words[2]: i += 7
    else: break

if S[i:] in words:  print('YES')
else:   print('NO')
    

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

int main() {
  string S,T;
  int i;
  float N,answer;
  
  cin >> N;

  if (N==1)
  {
    answer=1;
  }
  else if (fmod(N,2)==0)
  {
    answer=0.5;
  }
  else
  {
    answer=(N+1.0)/2.0/N;
  }
  
  
  cout << answer << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int bdsize;

bool hasBlank(vector<vector<int>> bd) {
    REP(i,bdsize) {
        REP(j, bdsize) {
            if (bd[i][j] == 0) return true;
        }
    }
    return false;
}

int nextInt;

void fillNext(vector<vector<int>> &bd, int x, int y) {
    if (!hasBlank(bd)) return;
    if (x >= bdsize) {fillNext(bd, 0, y); return;}
    if (y >= bdsize) {fillNext(bd, x, 0); return;}
    if (y < 0) {fillNext(bd, x, bdsize-1); return;}
    if (bd[x][y] != 0) {fillNext(bd, x+1, y-1); return;}
    bd[x][y] = nextInt;
    nextInt++;
    fillNext(bd, x+1, y+1);
}

void solve78(int n) {
    bdsize = n;
    vector<vector<int>> bd;
    REP(i,n) {
        vector<int> sub;
        REP(j,n) sub.push_back(0);
        bd.push_back(sub);
    }
    int lastx = n/2 + 1;
    int lasty = n/2;
    bd[lastx][lasty] = 1;
    nextInt = 2;
    fillNext(bd, lastx+1, lasty+1);
    REP(i,n) {
        REP(j,n) {
            printf("%4d", bd[i][j]);
        }
        cout << endl;
    }
}

int main() {
    int n;
    while (cin >> n, n) {
        solve78(n);
    }
    return 0;
}

Measured memory_bytes: 3296
ary = gets.chomp.split("")
odd = ary.select.with_index{|e, i|
i % 2 == 0
}
even = ary.select.with_index{|e, i|
i % 2 == 1
}

if (odd.include?("L") || even.include?("R"))
    print "No"
else
    print "Yes"
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
	cin>>a>>b>>k;
	if(a>=k)cout<<a-k<<" "<<b;
	else if(a+b>k)cout<<0<<" "<<b+a-k;
	else cout<<0<<" "<<0;
	return 0;
}

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

typedef long long ll;

const int MAX_N = 100005;
const ll M = 1000000007;

ll pot(ll x, ll y) {
    ll w = 1;

    while(y > 0) {
        if(y % 2 == 1) {
            w = (w * x) % M;
        }
        x = (x * x) % M;
        y /= 2;
    }

    return w;
}

ll T[MAX_N];

int main() {
    ll n, k;
    cin >> n >> k;

    ll w = 0;
    for(int i = k; i >= 1; i--) {
        T[i] = pot(k / i, n);
        for(int j = 2 * i; j <= k; j+=i) {
            T[i] -= T[j];
            T[i] += M;
            T[i] %= M;
        }
        w += (T[i] * i);
        w %= M;
    }

    cout << w;

    return 0;
}

Measured memory_bytes: 4396
main = do
    s <- getLine
    putStrLn $ unwords $ map show $ solve 1 s

solve :: Int -> [Char] -> [Int]
solve _ (_:[]) = [-1, -1]
solve i (a:b:[])
    | a == b = [i, i+1]
    | otherwise = [-1, -1]
solve i (a:b:c:xs)
    | a == b = [i, i+1]
    | a == c = [i, i+2]
    | otherwise = solve (i+1) (b:c:xs)

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

int *binary_search(int *array, size_t size, int value){
 int lower=0;
 int upper=(int)size - 1;

 while(lower <= upper){
  int mid = (lower + upper) /2;

  if( array[mid] == value){
    return &array[mid];
  }else if(array[mid] < value){
    lower = mid + 1;
  }else if(array[mid] > value){
    upper = mid - 1;
  }
 }

  return NULL;
}

int compare(int a, int b){
  if(a < b){
    return -1;
  }else if(a > b){
    return 1;
  }
  return 0;
}

//イテレーターを返す
int lower_bound(int *array, int len, int value){
  int l=0, r=len - 1;

  while(l <= r){
    int mid = l + (r-l)/2;
    int res = compare(array[mid], value);
    if(res == -1){
      l = mid + 1;
    }else{
      r = mid - 1;
    }
  }

  return l;
}

int upper_bound(int *array, int len, int value){
  int l=0, r=len-1;

  while(l <= r){
    int mid = l + (r-l)/2;
    int res= compare(array[mid], value);
    if(res <= 0) l= mid +1;
      else r = mid -1;
  }

  return l;
}

void merge_sort (int array[], int left, int right) {
  int i, j, k, mid;
  int work[100000];  //work array
  if (left < right) {
    mid = (left + right)/2;
    merge_sort(array, left, mid);  //sort left
    merge_sort(array, mid+1, right);  //sort right
    for (i = mid; i >= left; i--) { work[i] = array[i]; } //left section
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j]; //right section
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}
#define REP(i, n) for(int i=0; i < (int)n;i++)

int main(void){
  long n;
  int *a,*b,*c;

  scanf("%ld", &n);
  a = (int *)malloc(sizeof(int) * (n+1)); 
  b = (int *)malloc(sizeof(int) * (n+1)); 
  c = (int *)malloc(sizeof(int) * (n+1)); 

  for(size_t i = 0; i < n;i++){
    scanf("%d", (a+i));
  }
  merge_sort(a, 0, n-1);
  for(size_t i = 0; i < n;i++){
    scanf("%d", b+i);
  }
  for(size_t i = 0; i < n;i++){
    scanf("%d", c+i);
  }
  merge_sort(c, 0, n-1);
  for(size_t i =0;i<n;i++){
    //printf("%d ", a[i]);
  }
  //printf("\n");
  for(size_t i =0;i<n;i++){
    //printf("%d ", b[i]);
  }
  //printf("\n");
  for(size_t i =0;i<n;i++){
    //printf("%d ", c[i]);
  }
  //printf("\n");

  //上部の数字を選択、上部より大きい中部を選択、中部より大きい下部を選択
  long up,mid,low;
  long count=0;
  for(size_t i = 0;i < n;i++){
    //中央を基準とする
    mid = b[i];
    low = upper_bound(c, n, mid);
    up = lower_bound(a, n, mid);
    //printf("low:%ld\n", n - low);
    //printf("up:%ld\n", up);
    count += (n -low) * up;
  }
  printf("%ld\n",count);
  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void) {
	string in;
	int n = 0, w = 0, s = 0, e = 0;
	cin >> in;
	for (int i = 0; i < in.length(); ++i) {
		if (in[i] == 'S') {
			++s;
		}
		else if (in[i] == 'N') {
			++n;
		}
		else if (in[i] == 'W') {
			++w;
		}
		else if (in[i] == 'E') {
			++e;
		}
	}
	bool f = true;
	if ((s > 0 && n == 0) || (s == 0 && n>0)) {
		f = false;
	}
	if ((e > 0 && w == 0) || (e == 0 && w>0)) {
		f = false;
	}
	cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const ll INF=2e15;
const double PI=acos(-1);

vector<P> vectorCnt(vector<int> a) {
    sort(a.begin(),a.end());
    int n=a.size();
    vector<pair<int,int>> b;
    int cnt=1;
    rep(i,n-1) {
        if (a[i+1]!=a[i]) {
            b.push_back({cnt,a[i]});
            cnt=1;
        } else {
            ++cnt;
        }
    }
    b.push_back({cnt,a[n-1]});
    return b;
}

int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<int> a(n/2),b(n/2);
    rep(i,n) {
        if (i%2==0) cin >> a[i/2]; 
        else cin >> b[i/2];
    }
    vector<P> aa=vectorCnt(a);
    vector<P> bb=vectorCnt(b);
    aa.push_back({0,0});
    bb.push_back({0,0});
    sort(aa.begin(),aa.end(),greater<>());
    sort(bb.begin(),bb.end(),greater<>());
    int ans;
    if (aa[0].second!=bb[0].second) {
        ans=n-(aa[0].first+bb[0].first);
    } else {
        int ans1=n-(aa[0].first+bb[1].first);
        int ans2=n-(aa[1].first+bb[0].first);
        ans=min(ans1,ans2);
    }
    cout << ans << endl;
    


    return 0;
}


Measured memory_bytes: 5028
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let H: usize = sc.get();
    let W: usize = sc.get();
    if H == 1 || W == 1 {
        println!("{}", 1);
        return;
    }
    println!("{}", (H*W+1)/2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i,a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}

int main()
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m+1));
    REP(i,n){
        REP(j,m+1){
            cin >> a[i][j];
        }
    }
    ll ans=INF;
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        vector<int> v(m,0);
        ll tmp=0;
        REP(i,n)
        {
            if (bit & (1 << i))
            {
                REP(j,m){
                    v[j]+=a[i][j+1];
                }
                tmp+=a[i][0];
            }
        }
        REP(i,m){
            if(v[i]<x){
                tmp=INF;
            }
        }
        if(tmp<ans){
            ans=tmp;
        }
    }
    if(ans==INF){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)

//累積和的なものを考えると良いらしい
int main() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> a(2019, 0);
    ll fac = 1;
    ll cur = 0;
    a[cur]++;
    rep1(i, n){
        ll add = s[n-1-i] - '0';
        cur = (cur + fac*add) % 2019;
        fac = (fac*10) % 2019;
        a[cur]++;
    }
    ll ans = 0;
    rep1(i, a.size()){
        ans += a[i]*(a[i]-1)/2;
    }
    cout << ans << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<int,P> PP;

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

int n;
ll a[5];
string s;

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

	cin>>n;
	REP(i,n) {
		cin>>s;
		switch(s[0]) {
			case 'M':a[0]++;break;
			case 'A':a[1]++;break;
			case 'R':a[2]++;break;
			case 'C':a[3]++;break;
			case 'H':a[4]++;break;
		}
	}
	ll ans=0;
	REP(i,5) FOR(j,i+1,5) FOR(k,j+1,5) ans+=a[i]*a[j]*a[k];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
bool find1(vector< vector<int> >& C,vector< vector<int> >& check,int* findh,int* findw)
{
  for(int i = 0;i < C.size();++i)
    for(int j = 0;j < C[0].size();++j)
      if(C[i][j] == 1 && check[i][j] == 0){
	*findh = i;
	*findw = j;
	return true;
      }
  return false;
}
bool find2(vector< vector<int> >& C,vector< vector<int> >& check,int* findh,int* findw)
{
  if(C[*findh - 1][*findw - 1] == 1 && check[*findh - 1][*findw - 1] == 0){
    *findh -= 1;
    *findw -= 1;
    return true;
  }
  else if(C[*findh - 1][*findw] == 1 && check[*findh - 1][*findw] == 0){
    *findh -= 1;
    return true;
  }
  else if(C[*findh - 1][*findw + 1] == 1  && check[*findh - 1][*findw + 1] == 0){
    *findh -= 1;
    *findw += 1;
    return true;
  }
  else if(C[*findh][*findw - 1] == 1 && check[*findh][*findw - 1] == 0){
    *findw -= 1;
    return true;
  }
  else if(C[*findh][*findw + 1] == 1 && check[*findh][*findw + 1] == 0){
    *findw += 1;
    return true;
  }
  else if(C[*findh + 1][*findw - 1] == 1 && check[*findh + 1][*findw - 1] == 0){
    *findh += 1;
    *findw -= 1;
    return true;
  }
  else if(C[*findh + 1][*findw] == 1 && check[*findh + 1][*findw] == 0){
    *findh += 1;
    return true;
  }
  else if(C[*findh + 1][*findw + 1] == 1 && check[*findh + 1][*findw + 1] == 0){
    *findh += 1;
    *findw += 1;
    return true;
  }
  else return false;
}
int main()
{
  int w,h,findh,findw;
  stack< pair<int,int> > finish;
  queue<int> answer;
  while(cin >> w >> h && !(w == 0 && h == 0)){
    int howmany = 0;
    vector< vector<int> > C(h + 2,vector<int>(w + 2,0)),check(h + 2,vector<int>(w + 2,0)); 
    for(int i = 1;i <= h;++i)
      for(int j = 1;j <= w;++j)
	cin >> C[i][j];
    while(find1(C,check,&findh,&findw)){
      check[findh][findw] = 1;
      finish.push(make_pair(findh,findw));
      while(!finish.empty()){
	findh = finish.top().first;
	findw = finish.top().second;
	while(find2(C,check,&findh,&findw)){
	  finish.push(make_pair(findh,findw));
	  check[findh][findw] = 1;
	}
	finish.pop();
      }
      ++howmany;
    }
    answer.push(howmany);
  }
  for(;!answer.empty();answer.pop())
    cout << answer.front() << endl;
}

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

#define INF 1000000000

int n;
short zikan[2500][2500];
int result[2500];
int kakutei[2500];

int tansaku(int s,int g) {
	int i;
	for(i=0;i<n;i++) {
		result[i]=INF;
		kakutei[i]=0;
	}
	result[s]=0;
	for(i=0;i<n;i++) {
		int minst=0,minresult=INF;
		int j;
		for(j=0;j<n;j++) {
			if(!kakutei[j] && result[j]<minresult) {
				minst=j;
				minresult=result[j];
			}
		}
		kakutei[minst]=1;
		for(j=0;j<n;j++) {
			if(zikan[minst][j]>=0 && result[minst]+(int)zikan[minst][j]<result[j]) {
				result[j]=result[minst]+(int)zikan[minst][j];
			}
		}
	}
	return result[g];
}

typedef struct {
	int x,y;
} pos_t;

int getid(pos_t p,int w) {
	return p.y*w+p.x;
}

int getdist(pos_t a,pos_t b) {
	return abs(a.x-b.x)+abs(a.y-b.y);
}

pos_t start,goal;
int houzyu_num[2500];
pos_t houzyu[2500][2500];

int main(void) {
	int w,h;
	while(scanf("%d%d",&w,&h)==2 && (w|h)!=0) {
		int x,y;
		n=w*h;
		memset(houzyu_num,0,sizeof(houzyu_num));
		for(y=0;y<h;y++) {
			for(x=0;x<w;x++) {
				char now[12];
				scanf("%s",now);
				if(now[0]!='.') {
					if(now[0]=='S') {
						start.x=x;start.y=y;
					} else if(now[0]=='G') {
						goal.x=x;goal.y=y;
					} else {
						int nowid=atoi(now)-1;
						houzyu[nowid][houzyu_num[nowid]].x=x;
						houzyu[nowid][houzyu_num[nowid]].y=y;
						houzyu_num[nowid]++;
					}
				}
			}
		}
		for(x=0;x<w*h;x++) {
			for(y=0;y<w*h;y++) {
				zikan[x][y]=(x==y?0:-1);
			}
		}
		if(houzyu_num[0]>0) {
			for(x=0;x<houzyu_num[0];x++) {
				zikan[getid(start,w)][getid(houzyu[0][x],w)]=(short)getdist(start,houzyu[0][x]);
			}
			for(y=1;houzyu_num[y]>0;y++) {
				int i,j;
				for(i=0;i<houzyu_num[y-1];i++) {
					for(j=0;j<houzyu_num[y];j++) {
						zikan[getid(houzyu[y-1][i],w)][getid(houzyu[y][j],w)]=(short)getdist(houzyu[y-1][i],houzyu[y][j]);
					}
				}
			}
			for(x=0;x<houzyu_num[y-1];x++) {
				zikan[getid(houzyu[y-1][x],w)][getid(goal,w)]=(short)getdist(houzyu[y-1][x],goal);
			}
		} else {
			zikan[getid(start,w)][getid(goal,w)]=(short)getdist(start,goal);
		}
		printf("%d\n",tansaku(getid(start,w),getid(goal,w)));
	}
	return 0;
}

Measured memory_bytes: 60348
#include <bits/stdc++.h>
using namespace std;
string S;
long long bcount=0,ans=0;
int main(){
  cin >> S;
  for(long long i=0;i<S.size();i++){
    if(S[i]=='B') bcount++;
    else ans += bcount;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
    char s[3];
    char t[3];
    scanf("%s",s);
    scanf("%s",t);
    int count;
    count=0;
    int a;
    for(a=0;a<3;a++){
            if(s[a]==t[a]){count++;}
            else{}
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX_N = 405;
const int dX[4] { -1, 1,  0, 0 };
const int dY[4] {  0, 0, -1, 1 };

int h, w;
bool t[MAX_N][MAX_N];
vector<pair<int, int>> g[MAX_N][MAX_N];
bool used[MAX_N][MAX_N];
ll cntB = 0, cntW = 0;

void dfs(int i, int j)
{
	used[i][j] = true;
	if (t[i][j])
		cntB++;
	else
		cntW++;
	for (const auto& p : g[i][j])
		if (!used[p.first][p.second])
			dfs(p.first, p.second);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		string s; cin >> s;
		for (int j = 0; j < w; j++)
			t[i][j] = s[j] == '#';
	}

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			for (int k = 0; k < 4; k++)
			{
				int nI = i + dX[k], nJ = j + dY[k];
				if (nI < 0 || nI >= h || nJ < 0 || nJ >= w)
					continue;
				if (t[nI][nJ] == t[i][j])
					continue;
				g[i][j].emplace_back(nI, nJ);
			}
		}

	ll result = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			if (used[i][j])
				continue;
			cntB = 0; cntW = 0;
			dfs(i, j);
			result += cntB * cntW;
		}
	cout << result << endl;
}

Measured memory_bytes: 14976