akhauriyash/Code-Regression huggingface dataset:
/**
 * auther: moririn_cocoa
 */
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main(int argc, char* argv[]) {
  
  int a;
  int b;
  int c;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  if ( a + b == c ) {
    
    cout << "Yes" << endl;
  }
  
  else if ( a + c == b ) {
    
    cout << "Yes" << endl;
  }
  
  else if ( b + c == a ) {
    
    cout << "Yes" << endl;
  }
  
  else {
    
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
def multiple_sum(x, n):
    # x + 2x + ... + kx(<= n)
    k = n // x
    return x * (k + 1) * k // 2


def solve(N: int):
    ans = 0
    for i in range(1, N + 1):
        ans += multiple_sum(i, N)
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int cnt = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
}



Measured memory_bytes: 2760
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define read(n) scanf("%d", &n)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b;
  read(a);
  read(b);

  int n = b - a;
  int sum = (1 + n) * n / 2;
  int ans = sum - b; 
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

void read(int *n,int A[]){
	scanf("%d",n);
	int i;
	for (i = 0; i < *n; i++) {
		scanf("%d", &A[i]);
	}
}

void profitchange(int *profit,int *max,int *min){
	if(*profit<*max-*min){
		*profit = *max - *min;
	}
}

int getprofit(int n,int A[]){
	int i,profit,max,min;
	profit = A[1]-A[0];
	max=min=A[0];
	for(i=0;i<n;i++){
		if(A[i]<min){
			max=min=A[i];
		}else if(A[i]>max){
			max = A[i];
			profitchange(&profit,&max,&min);
		}else if(A[i]==A[i-1]){
			profitchange(&profit,&max,&min);
		}
	}

	return profit;
}

int main(){
	int n,A[200000];
	read(&n,A);
	printf("%d\n",getprofit(n,A));

	return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 	int N;
 	cin >> N;
 	vector<pi> r(N), b(N);
 	for (int i = 0; i < N; i++) cin >> r[i].first >> r[i].second;   
 	for (int i = 0; i < N; i++) cin >> b[i].first >> b[i].second;   
 	sort(r.begin(),r.end(),greater<pi>());
 	sort(b.begin(),b.end());
 	int ans = 0, idx = N-1;
 	multiset<int> ms;
 	for (int i = 0; i < N; i++) {
 		while (idx >= 0 && b[idx].first > r[i].first) {
 			ms.emplace(b[idx].second);
 			idx--;
 		}
 		auto t = ms.upper_bound(r[i].second);
 		if (t != ms.end()) {
 			ans++;
 			ms.erase(t);
 		}
 	}
 	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define li 1500 * 1000
int hh[li + 1], ww[li + 1];
int main() {
    while (1) {
        int n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        int h[n], w[m];
        for (int i = 0; i < n; ++i) {
            cin >> h[i];
        }
        for (int i = 0; i < n; ++i) {
            int sum = 0;
            hh[sum + h[i]]++;
            sum += h[i];
            //cout << "sum " << sum << endl;
            for (int j = i + 1; j < n; ++j) {
                hh[sum + h[j]]++; //先のhまでいる
                sum += h[j];
                //cout << "sum " << sum << endl;
            }
        }
        for (int i = 0; i < m; ++i) {
            cin >> w[i];
        }
        for (int i = 0; i < m; ++i) {
            int sum = 0;
            ww[sum + w[i]]++;
            sum += w[i];
            for (int j = i + 1; j < m; ++j) {
                ww[sum + w[j]]++;
                sum += w[j];
            }
        }
        long long ans = 0;
        for (int i = 1; i <= li; ++i) {
            //if (i <= 10) cout << hh[i] << " " << ww[i] << endl;
            ans += (long long)hh[i] * ww[i];
        }
        cout << ans << endl;
        //initialize
        for (int i = 1; i <= li; ++i) {
            hh[i] = 0;
        }
        for (int i = 1; i <= li; ++i) {
            ww[i] = 0;
        }
    }
    return 0;
}



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

int gcd(long long int a,long long int b){
  if(a%b==0)
    return(b);
  else
    return(gcd(b,a%b));
}

int main(){
  long long int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  long long int x,y,z;
  
  x=b/c-(a-1)/c+b/d-(a-1)/d;
  y=c*d/gcd(c,d);
  z=b/y-(a-1)/y;
  
  cout << b-a-x+z+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){

    int W, H , x, y, r;
    cin >> W >> H >> x >> y >> r;

    if ((x >= r) && (y >= r) && (y <= H-r) && (x <= W-r)) cout << "Yes" << endl;

    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

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

	/* 入力 */
	int n = scan.nextInt();
	int m = scan.nextInt();
	String[] a = new String[n];
	String[] b = new String[m];
	for(int i = 0; i < n; i++){
	    a[i] = scan.next();
	}
	for(int i = 0; i < m; i++){
	    b[i] = scan.next();
	}

	int judge = -1;
	out: for(int i = 0; i < n-m+1; i++){
	    for(int j = 0; j < n-m+1; j++){
		/* Bの重ねる初期位置決定 */
		int flag = 1;
		for(int k = 0; k < m; k++){
		    for(int l = 0; l < m; l++){
			/* Bの重ねる位置を移動させていく */
			if(a[i+k].charAt(j+l) != b[k].charAt(l)){
			    flag = -1;
			    break;
			}
		    }
		    if(flag == -1){
			break;
		    }
		}
		if(flag == 1){
		    judge = 1;
		    break out;
		}	
	    }
	}

	if(judge == 1){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}
	    


Measured memory_bytes: 22612
s = input()
t = input()
ls = len(s)
lt = len(t)
#print(ord('a'))
#print(chr(98))
ss = []
ss1 = [[] for _ in range(26)]
ss2 = [[] for _ in range(26)]
for i in range(ls):
  ss1[ord(s[i]) - 97].append(i)
  ss2[ord(s[i]) - 97].append(i+ls)
for k in range(26):
  ss.append(ss1[k] + ss2[k])
ans = 0
mans = 0
import bisect
for j in range(lt):
  now = ord(t[j]) - 97
  if ss[now] == []:
    print(-1)
    break
  here = bisect.bisect_left(ss[now],mans)
  ans += ss[now][here] - mans + 1
  mans = ans % ls
else:
  print(ans)

Measured memory_bytes: 13300
package main

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

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func get_int(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type node struct {
	n, depth int
}

func main() {
	var n, m, s, t int
	sc := wordScanner()
	n = get_int(sc)
	m = get_int(sc)
	us := make([]int, m)
	vs := make([]int, m)
	for i := range us {
		us[i] = get_int(sc) - 1
		vs[i] = get_int(sc) - 1
	}
	s = get_int(sc) - 1
	t = get_int(sc) - 1

	g := make([][]int, 3*n)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for i, u := range us {
		g[u] = append(g[u], n+vs[i])
		g[n+u] = append(g[n+u], 2*n+vs[i])
		g[2*n+u] = append(g[2*n+u], vs[i])
	}

	visit := make([]bool, 3*n)
	mins := make([]int, 3*n)

	q := make([]node, 0)
	q = append(q, node{n: s, depth: 0})

	for len(q) > 0 {
		e := q[0]
		q = q[1:]
		first_visit := !visit[e.n]
		visit[e.n] = true
		if first_visit || e.depth < mins[e.n] {
			mins[e.n] = e.depth
			for _, v := range g[e.n] {
				q = append(q, node{n: v, depth: e.depth + 1})
			}
		}
	}

	if !visit[t] {
		fmt.Println(-1)
	} else {
		fmt.Println(mins[t] / 3)
	}
}


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

typedef long long ll;

const int Maxn = 150;

int x;

int main()
{
    scanf("%d", &x);
    for (ll a = -Maxn; a <= Maxn; a++)
        for (ll b = -Maxn; b <= Maxn; b++)
            if (a * a * a * a * a - b * b * b * b * b == x) {
                printf("%lld %lld\n", a, b);
                return 0;
            }
    return 0;
}


Measured memory_bytes: 3844
l,r = map(int,input().split())
a = 2019
for i in range(l,r+1) :
    if a == 0:
        break
    else :
        for j in range(i+1,r+1) :
            x = (i*j)%2019
            if x == 0 :
                a = x
                break
            else :
                if x<=a:
                    a = x
print(a)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int R,G;

  cin>>R>>G;

  cout<<G*2-R<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	vector<string> ss;
	REP(i,(ll)s.size()-((ll)t.size()-1)) {
		string buf=s;
		bool d=true;
		REP(j,(ll)t.size()) {
			if(buf[i+j]==t[j]||buf[i+j]=='?') buf[i+j]=t[j];
			else d=false;
		}
		if(d) {
			REP(j,(ll)buf.size()) if(buf[j]=='?') buf[j]='a';
			ss.pb(buf);
		}
	}
	sort(ALL(ss));
	if(ss.size()==0) cout<<"UNRESTORABLE"<<endl;
	else cout<<ss[0]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	
	int s;
	int h_r,m_r,s_r;
	
	
	scanf("%d",&s);
	
	h_r = s / 3600;
	
	m_r = (s%3600) / 60;
	
	s_r = s - (3600*h_r + 60 * m_r);
	
	printf("%d:%d:%d\n",h_r,m_r,s_r);
	
    return 0;
}


Measured memory_bytes: 2732
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long w, h, x, y;
    cin >>w >>h >>x >>y;
    bool flag = (x+x == w) && (y+y == h);
    cout <<fixed <<setprecision(6) <<(double(w)*double(h))/2 <<" " <<flag;
    return 0;
}


Measured memory_bytes: 256
x,n=map(int, input().split())
if n==0:
  print(x)
  exit()
p=list(map(int, input().split()))
ans=10**10
for i in range(102):
  if not x-i in p:
    print(x-i)
    exit()
  if not x+i in p:
    print(x+i)
    exit()

Measured memory_bytes: 9216
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

// TEMPLATE STARTS BELOW

#define DEFMOD(mod, type) typedef ModInt<mod, int> type;     \
                          type operator "" _m(unsigned long long x) {   \
                              type res = x; return res; \
                          }

template<int mod, class itype> struct ModInt {
    int val;
    ModInt() {
        val = 0;
    }
    ModInt(int a) {
        val = a % mod;
    }
};

/* MODIFY AS NEEDED */

DEFMOD(998244353, mi)

template<int mod, class itype> ModInt<mod, itype> fpow(ModInt<mod, itype> base, int exponent)
{
    ModInt<mod, itype> ans = 1_m;
    ModInt<mod, itype> cur = base;
    while (exponent) {
        if (exponent & 1) ans = ans * cur;
        cur = cur * cur; exponent >>= 1;
    }
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator+(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ll val = (ll)(a.val) + (ll)(b.val);
    if (val >= mod) val -= mod;
    ans.val = val; return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator-(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = a.val - b.val;
    if (ans.val < 0) ans.val += mod;
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator*(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = ((ll)(a.val) * (ll)(b.val)) % (ll)mod;
    return ans;
}

// PRIME MOD ONLY!
template<int mod, class itype> ModInt<mod, itype> operator/(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
#ifndef ONLINE_JUDGE
    if (b.val == 0) {
        fprintf(stderr, "Division by zero :(\n"); abort();
    }
#endif
    return a * fpow(b, mod - 2);
}

mi f[3005][3005];

int main()
{
    int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
    for (int i = a; i <= c; i++) {
        for (int j = b; j <= d; j++) {
            if (i == a && j == b) {
                f[i][j] = 1_m; continue;
            }
            if (i == a) {
                f[i][j] = fpow((mi)(a), j - b); continue;
            }
            if (j == b) {
                f[i][j] = fpow((mi)(b), i - a); continue;
            }
            f[i][j] = f[i-1][j] + f[i][j-1] + (mi)(j-1) * f[i-1][j] +
                (mi)(i-1) * f[i][j-1] - (mi)(i-1) * (mi)(j-1) * f[i-1][j-1];
        }
    }
    printf("%d", f[c][d].val);
    return 0;
}


Measured memory_bytes: 37000
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

int main(){
	//fri("a.gir");
	//fro("a.cik");
	set<int> st;
	for(int i=1;i<=9;i++){
		for(int j=i;j<=9;j++){
			st.insert(i*j);
		}
	}
	int n;
	cin>>n;
	if(st.count(n)){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << c  << "  "<< a << " " << b << endl;
}


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

int main() {
  int n , m ,x;
  cin >> n >> m >> x;
  vector <int> a(m);
  for (int i=0 ; i<m ; i++){
    cin >> a.at(i) ;
  }
  int cost_s=0 , cost_g=0 ;
   for (int i=0 ; i<m ; i++){
    if (a.at(i)<x){
      cost_s ++ ;
    }else if ( a.at(i)>x){
      cost_g ++ ;
    }
   }
  cout << min ( cost_s,cost_g) << endl; 
}

Measured memory_bytes: 3632
<?php

fscanf(STDIN, "%d %d", $k, $s);
$cnt = 0;
for ($x = 0; $x <= $k; $x++) {
    for ($y = 0; $y <= $k; $y++) {
        
        $z = $s-$x-$y;
        
        if(($z>=0)&&($z<=$k)){
             $cnt++;
        }
    }
}

    echo $cnt;
    echo "\n";
?>

Measured memory_bytes: 3576
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

string s;
int x, y;
bool git[2];

int main() {
  init_ios();
  cin >> s;
  x = 10*(s[0]-'0')+(s[1]-'0');
  y = 10*(s[2]-'0')+(s[3]-'0');
  if (y > 0 && y <= 12)
    git[0] = true;
  if (x > 0 && x <= 12)
    git[1] = true;
  if (git[0] && git[1])
    cout<<"AMBIGUOUS\n";
  else if (!git[0] && !git[1])
    cout<<"NA\n";
  else if (git[0])
    cout<<"YYMM\n";
  else
    cout<<"MMYY\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;

	int t;
	for (int i = 0; i < n; i++) {
		cin >> t;
		if (t % 2 == 0) {
			if (t % 3 != 0 && t % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int a=700;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='o')
            a=a+100;
    }
    cout<<a<<endl;
    return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T, typename U>
void print1(T Array, U size) {
  for (int i = 0; i < size; i++) {
    cout << Array[i] << " ";
  }
  cout << endl;
}

template<typename T>
void print(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

int n;

int rec(int stage) {
  if (stage == 0) {
    return 1;
  }

  int ans = 0;

  for (int i = 1; i <= 3; i++) {
    if (stage - i < 0) continue;
    ans += rec(stage - i);
  }

  return ans;
}

signed main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    int t = (rec(n) + 3650 - 1) / 3650;
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 3120
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

dp_mod_k = {}

score = 0
for i in range(n):
    if i % k in dp_mod_k:
        dp_r, dp_s, dp_p = dp_mod_k[i % k]
    else:
        dp_r, dp_s, dp_p = 0, 0, 0
    opponent_hand = t[i]
    if opponent_hand == "r":
        new_dp_r = max(dp_s, dp_p)
        new_dp_s = max(dp_r, dp_p)
        new_dp_p = max(dp_r, dp_s) + p
    elif opponent_hand == "s":
        new_dp_r = max(dp_s, dp_p) + r
        new_dp_s = max(dp_r, dp_p)
        new_dp_p = max(dp_r, dp_s)
    else:
        new_dp_r = max(dp_s, dp_p)
        new_dp_s = max(dp_r, dp_p) + s
        new_dp_p = max(dp_r, dp_s)
    dp_mod_k[i % k] = [new_dp_r, new_dp_s, new_dp_p]
    if i + k >= n:
        score += max(new_dp_r, new_dp_s, new_dp_p)

print(score)

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

const int INF = 0x7fffffff;
int res = INF,k;

void dfs(int n, int num)
{
    if(n == 0)
    {
        res = min(res,num);
        return;
    }
    dfs(n-1,num*2);
    dfs(n-1,num+k);
}

int main()
{
    int n;
    cin >> n >> k;
    dfs(n,1);
    cout << res << endl;
    return 0;
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  static const ll MAX = 100010LL;
  ll N, M, H[MAX], A[MAX], B[MAX], good[MAX];

  void init() {
    scanf("%lld %lld", &N, &M);
    rep(i, N) scanf("%lld", H+i);
    rep(i, M) {
      scanf("%lld %lld", A+i, B+i);
      A[i]--;
      B[i]--;
    }
  }

  void solve() {
    rep(i, N) good[i] = true;
    rep(i, M) {
      if(H[A[i]] <= H[B[i]]) good[A[i]] = false;
      if(H[B[i]] <= H[A[i]]) good[B[i]] = false;
    }
    ll ans = 0;
    rep(i, N) if(good[i]) ans++;
    cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 6780
/*
    Problem 94
    https://onlinejudge.u-aizu.ac.jp/problems/1149
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* class */
class Cake {
    public:
    int w, d, S, old;
    Cake () {}
    Cake(int w, int d, int old):
    w(w), d(d), old(old) { S = w * d; }
    bool operator < (const Cake &c) const {
        if (old == c.old) return S < c.S;
        return old < c.old;
    }
    vector<int> calcCutPosition (int l) {
        int pos = l % (2 * (w+d));
        int head = w, tail = 0;
        int len1, len2, i;
        for (i = 0; i < 4; i++) {
            len1 = head - pos, len2 = pos - tail;
            if (len1 > 0 && len2 > 0) break;
            tail = head;
            head += ((i % 2) ? w : d);
        }
        vector<int> ret = {i%2, len1, len2};
        return ret;
    }
};
/* global variables */
int n, w, d;
/* function */
void input() {cin >> n >> w >> d;}
bool check() {return n == 0 && w == 0; }
void solve() {
    // init
    vector<Cake> C;
    C.push_back(Cake(w, d, 0));
    // Cut
    for (int i = 1; i <= n; i++) {
        int p, s;
        cin >> p >> s; p--;

        Cake target = C[p];
        C.erase(C.begin() + p);

        vector<int> ret = target.calcCutPosition(s);
        if (ret[0]) {
            C.push_back(Cake(target.w, ret[1], i));
            C.push_back(Cake(target.w, ret[2], i));
        }
        else {
            C.push_back(Cake(ret[1], target.d, i));
            C.push_back(Cake(ret[2], target.d, i));
        }

        sort(C.begin(), C.end());

    }

    vector<int> A;
    for (Cake c : C) A.push_back(c.S);
    sort(A.begin(), A.end());
    for (int i = 0; i < A.size(); i++) { if (i) cout << ' '; cout << A[i]; }
    cout << '\n';

}
/* main */
int main(){
    while (1) {
        input();
        if (check()) break;
        solve();
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>A>>B;
    cout<<(N - A)%B<<endl;
}

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

using namespace std;

int main()
{
    uint32_t N, tmp;   
    vector<uint32_t> d;
    
    uint64_t sum = 0;
    
    cin >> N;
    
    for(auto i = 0; i < N; i++){
        cin >> tmp;
        d.push_back(tmp);
    }
    
    for(auto i = 0; i < N - 1; i++){
        for(auto j = i+1; j < N; j++){
            sum+= (d[i] * d[j]);
            //cout << (d[i] * d[j]) << endl;
        }
    }
    cout << sum << endl;
    
    return 0;
    
}


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

#define INF INT_MAX

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

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

    string s;
    cin >> s;
    
    bool f = false;
    for(int i = 0;i < s.size()-1;i++){
        if(s[i] == s[i+1]){
            f = true;
            break;
        }
    }
    string ans;
    ans = f? "Bad":"Good";
 
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int a;
  string s;
  cin>>a>>s;
  if(a<3200)s="red";
  cout<<s<<endl;
  return 0;
}

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

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


int main() {

int x,a;
cin >> x >> a;

if(x<a)cout << 0 << endl;
else cout << 10 << endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop for(;;)
#define rep(i, n) for(long i = 0; i < (long)(n); ++i)
typedef std::vector<long> LI;

struct Solver {
   void solve() {
      long n, m; std::cin >> n >> m;
      if( n == 0 and m == 0 ) exit(0);
      LI cs[1123];
      LI ss(m), ks(m);
      LI minP(n), maxP(n);
      rep(i, m) {
         std::cin >> ss[i] >> ks[i];
         cs[i].resize(ks[i]);
         rep(k, ks[i]) {
            std::cin >> cs[i][k];
            cs[i][k] -= 1;
            maxP[cs[i][k]] += ss[i];
         }
         if( ks[i] == 1 ) {
            minP[cs[i][0]] += ss[i];
         }
      }
      long res = 0;
      rep(i, n) {
         rep(k, n) {
            if( i == k ) continue;
            res = std::max(res, maxP[i] - minP[k] + 1);
         }
      }
      printf("%ld\n", res);
   }
};

int main() { loop std::shared_ptr<Solver>(new Solver())->solve(); }

Measured memory_bytes: 3748
import math
a,b,h,m = map(int,input().split())

sh = (h * 60 + m) * 360 / (12 * 60) 
lo = 360 / 60 * m 
dif = abs(sh-lo)
ce = min(dif, 360-dif)

wa = a**2 + b**2
mi = 2 * a * b * math.cos(math.radians(ce))
aa = wa - mi
ans = pow(aa, 0.5)
print(ans)

Measured memory_bytes: 9540
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}



signed main() {
	int n;
	cin >> n;
	int l[n+1];
	l[0] = 2;
	l[1] = 1;
	FOR (i,2,n+1) {
		l[i] = l[i-1] + l[i-2];
	}
	cout << l[n] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	string S = res();
	bool OK = S.length() % 2 == 0;
	for(int i=0;i<S.length();i++){
		if(i % 2 == 0){
			OK &= S[i] == 'h';
		}
		else{
			OK &= S[i] == 'i';
		}
	}
	if(OK){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    vvi c(3, vi(3));

    fo(i, 3) fo(j, 3) cin >> c[i][j];

    bool pos = true;
    int dif = c[2][0] - c[2][1];
    fo(i, 2) {
        if ( c[i][0] - c[i][1] != dif ) pos = false;
    }
    dif = c[2][1] - c[2][2];
    fo(i, 2) {
        if ( c[i][1] - c[i][2] != dif ) pos = false;
    }

    cout << (pos ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 3624
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    double xp1, xp2, yp1, yp2;
    int q;
    double[] xp, yp;
    double ansx, ansy, t;
    int i;

    xp1 = sc.nextDouble();
    yp1 = sc.nextDouble();
    xp2 = sc.nextDouble();
    yp2 = sc.nextDouble();
    q = sc.nextInt();
    xp = new double[q];
    yp = new double[q];

    for(i = 0;i < q;i++){
      xp[i] = sc.nextDouble();
      yp[i] = sc.nextDouble();
    }
    sc.close();
/*  want to solve
ansx = xp1 + t * (xp2 - xp1)
ansy = yp1 + t * (yp2 - yp1)
(xp2 - xp1) * (xp[i] - ansx) + (yp2 - yp1) * (yp[i] - ansy) = 0
  VV
t((xp2-xp1)^2 + (yp2-yp1)^2) = (xp2-xp1)(xp[i]-xp1) + (yp2-yp1)(yp[i]-yp1)
*/

    for(i = 0;i < q;i++){
      t = (xp2 - xp1) * (xp[i] - xp1) + (yp2 - yp1) * (yp[i] - yp1);
      t = t / ((xp2 - xp1) * (xp2 - xp1) + (yp2 - yp1) * (yp2 - yp1));
      ansx = xp1 + t * (xp2 - xp1);
      ansy = yp1 + t * (yp2 - yp1);
      System.out.printf("%.10f %.10f%n", ansx, ansy);
    }

  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 38028
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 1e9 + 7;



int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vector<int> v(n);
    trav(i, v) cin >> i;
    ll sum = 0;
    int mx = -1;
    FOR(i, 0, n)
    {
        if (v[i] < mx)
        {
            sum += (mx - v[i]);
        }
        else
        {
            mx = v[i];
        }
    }
    cout << sum;

    return 0;
}





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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    int k;
    for (int i = 0; i < N-1; i++) {
        cin >> k;
        vec[k-1]++;
    }
    for(int x : vec){
        cout << x << endl;
    }
    return 0;
}

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

struct data {
  int x, y, c, d;
};
bool operator<(const data &l, const data &r) {
  if(l.c != r.c)
    return l.c > r.c;
  else if(l.x != r.x)
    return l.x > r.x;
  return l.y > r.y;
}

int w, h;
vector<vector<int>> s;
int c[4] = {0};
int d[4] = {0, 1, 0, -1};
int dis[33][33][4] = {0};
priority_queue<data> pq;

void reset();
bool ch(int x, int y);
int solve();

int main() {
  while(1) {
    cin >> w >> h;
    if(w + h == 0) break;
    reset();
    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j) cin >> s[i][j];
    for(int i = 0; i < 4; ++i) cin >> c[i];
    cout << solve() << endl;
  }
  return 0;
}

void reset() {
  while(!pq.empty()) pq.pop();
  s.resize(h);
  for(int i = 0; i < h; ++i) s[i].assign(w, 0);
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      for(int k = 0; k < 4; ++k) dis[i][j][k] = 1e9;
}
bool ch(int x, int y) {
  return x >= 0 && x < h && y >= 0 && y < w;
}

int solve() {
  int ans = 1e9;
  pq.push({0, 0, 0, 0});
  while(!pq.empty()) {
    data now, nextd;
    now = pq.top();
    pq.pop();
    if(now.c >= dis[now.x][now.y][now.d]) continue;
    dis[now.x][now.y][now.d] = now.c;
    for(int i = 0; i < 4; ++i) {
      nextd = now;
      nextd.x += d[i];
      nextd.y += d[i ^ 1];
      if(!ch(nextd.x, nextd.y)) continue;
      if(s[now.x][now.y] == 4 ||
         (s[now.x][now.y] + now.d) % 4 != i)
        nextd.c += c[(i + 4 - now.d) % 4];
      nextd.d = i;
      if(nextd.x == h - 1 && nextd.y == w - 1) {
        ans = min(ans, nextd.c);
        continue;
      }
      pq.push(nextd);
    }
  }
  return ans;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  int l[n], r[n];
   for(int i=0; i<n; i++){
  cin >> l[i] >> r[i];
   }
  long sum=0;
  for(int i=0; i<n; i++){
  	sum= sum+(r[i]-l[i]+1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()

int ni() {
    int i;
    cin >> i;
    return i;
}

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

    vector<int> a;
    REP(i, N) a.push_back(ni());

    sort(ALL(a));
    a.push_back(-1);

    ll ans = 0;
    ll count = 0;
    FOR(i, 0, N) {
        count++;
        if (a[i+1] != a[i]) {
            if (count >= a[i]) ans += (count-a[i]);
            else ans += count;
            count = 0;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<int> A(N), B(N);
  for(int i = 0; i < N; ++i) std::cin >> A[i] >> B[i];
  auto calc = [&](int x)->int64_t {
    int64_t res = 0;
    for(int i = 0; i < N; ++i) if((A[i]&x)==A[i]) res += B[i];
    return res;
  };
  int64_t ans = calc(K);
  for(int i = 29; i >= 0; --i) {
    int mask = 1<<i;
    if(0 == (mask&K)) continue;
    int cur = (K&-mask)-1;
    ans = std::max(ans, calc(cur));
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>

using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
int main() {
    cin >> n;
    vector<double> x(n, 0.0);
    vector<double> y(n, 0.0);
    for(int i = 0; i < n; ++i) cin >> x.at(i) >> y.at(i);

    vector<int> ppl(n, 0);
    double bunbo = 1.0;
    for(int i = 0; i < n; ++i) {
        ppl.at(i) = i;
        bunbo *= (double)(i+1);
    }
    double sumlen = 0.0;
    do {
        double xstart = x.at(ppl.at(0)); double ystart = y.at(ppl.at(0));
        for(int i = 0; i < n; ++i) {
            double xx = powl((xstart-x.at(ppl.at(i))), 2);
            double yy = powl((ystart-y.at(ppl.at(i))), 2);
            sumlen += sqrtl(xx+yy);
            xstart = x.at(ppl.at(i));
            ystart = y.at(ppl.at(i));
        }
    }while(next_permutation(ppl.begin(), ppl.end()));

    double ans = sumlen / bunbo;
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
int n;
string s;
int main()
{
    cin>>n>>s;
    int i=0,j=n-1,ans=0;
    while(i<j)
    {
        while(i<j && s[i]=='R')
            i++;
        while(i<j && s[j]=='W')
            j--;
        if(i<j) ans++;
        i++,j--;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3764
/*
g++ -std=c++11 -o2 -Wall ABC099C.cpp -o ./out/ABC099C.out
./out/ABC099C.out
*/

#include <bits/stdc++.h>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

int main(){
//    freopen("./input/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = n;
    for (int n1 = 0; n1 <= n; ++n1) {
      int temp = 0;
      int t1 = n1;
      for (int i = 1;; ++i) {
        temp += t1 % 6;
        t1 /= 6;
        if (t1 <= 0) break;
      }
      int n2 = n - n1;
      int t2 = n2;
      for (int i = 1;; ++i) {
        temp += t2 % 9;
        t2 /= 9;
        if (t2 <= 0) break;
      }
      if (temp < ans) {
        ans = temp;
      }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


using namespace std;
typedef long long ll;
const int MX=1e6+7;
const long double eps=-0.00000001;
int a[MX];

vector <char> v;
int main()
{
    int n;
    cin>>n;
ll ans=1e9;
    for ( int i=0 ; i<n ; i++ ) { cin>>a[i]; }

    for ( int j=-100 ; j<=100 ; j++ )
    {
        ll c=0;
        for ( int i=0 ;i<n ; i++ )
        {
            c += ( a[i]-j )*( a[i]-j );
        }
        ans = min ( ans , c );

    }

    cout<<ans;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,w[111],mx,sum1,sum2,ans=1e9;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>w[i];
		mx=max(mx,w[i]);
	}
	for(int i=0;i<n;i++)
	{
		sum1=0;
		sum2=0;
		for(int j=0;j<n;j++)
		{
			if(j<=i)
			{
				sum1+=w[j];
			}
			else
			{
				sum2+=w[j];
			}
		}
		ans=min(ans,abs(sum1-sum2));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a = int(input())
cards = [[False for x in range(13)] for y in range(4)]
for i in range(a):
    s, v = map(str, input().split())
    u = int(v)
    if s == 'S':
        cards[0][u-1] = True
    elif s == 'H':
        cards[1][u-1] = True
    elif s == 'C':
        cards[2][u-1] = True
    elif s == 'D':
        cards[3][u-1] = True
    else:
        pass

for j in range(13):
    if cards[0][j]:
        continue
    else:
        print("S ", end="")
        print(j+1)

for j in range(13):
    if cards[1][j]:
        continue
    else:
        print("H ", end="")
        print(j+1)

for j in range(13):
    if cards[2][j]:
        continue
    else:
        print("C ", end="")
        print(j+1)

for j in range(13):
    if cards[3][j]:
        continue
    else:
        print("D ", end="")
        print(j+1)




Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
vector<int> ve[N];
priority_queue<int> qe;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b;
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		if(m-a+1>0)
			ve[m-a+1].push_back(b);
	}
	int sum=0;
	for(int i=m;i>=1;--i)
	{
		for(int j=0;j<ve[i].size();++j)
		qe.push(ve[i][j]);
		if(qe.size())
		sum+=qe.top(),qe.pop();
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 30220
object Main extends App {
  val nrInput =  scala.io.StdIn.readLine()
  val nrArray = nrInput.split(" ").map(_.toInt).toSeq
  val n = nrArray(0)
  val r = nrArray(1)
  if (n >= 10) {
    println(r)
  } else {
    println((10 - n) * 100 + r)
  }

}


Measured memory_bytes: 25524
n = int(input())
a = list(map(int, input().split()))
dif = 0
print
for i in range(1, n):
    dif += abs(a[i] - a[i-1])

for i in range(n):
    if i == 0:
        ans = dif - (abs(a[i+1]-a[i])) + abs(a[1]) + abs(a[n-1])
    elif i == n-1:
        ans = dif - (abs(a[i-1]-a[i])) + abs(a[0]) + abs(a[n-2])
    else:
        ans = dif - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])) + abs(a[i-1]-a[i+1]) + abs(a[0]) + abs(a[n-1])
    print(ans)


Measured memory_bytes: 14172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int progA[] = new int[n];
		int progB[] = new int[n];
		for(int i = 0; i < n; i++) {
			progA[i] = sc.nextInt();
		}
		int q = sc.nextInt();

		for(int i = 0; i < q; i++) {
			int b = sc.nextInt();
			int e = sc.nextInt();
			int t = sc.nextInt();
			for(int k = 0; k < e - b; k++) {
				progB[b + k] = progA[b + k];
				progA[b + k] = progA[t + k];
				progA[t + k] = progB[b + k];
			}
		}
		for(int j = 0; j < progA.length; j++) {
			if(j != 0) System.out.print(" ");
			System.out.print(progA[j]);
		}
		System.out.println();
	}

}



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

using namespace std;

using int64 = long long;

int main() {
  int N, A[100000], B[100000];

  cin >> N;

  int64 all = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    all += A[i];
  }

  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    if(A[i] > B[i]) {
      ret = max(ret, all - B[i]);
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 384