akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main() {
    int a, b;
    char op;
    while (true) {
        std::cin >> a >> op >> b;
        if (op == '?') break;
        if (op == '+') {
            std::cout << a + b << std::endl;
        } else if (op == '-') {
            std::cout << a - b << std::endl;
        } else if (op == '*') {
            std::cout << a * b << std::endl;
        } else if (op == '/') {
            std::cout << a / b << std::endl;
        }
    }
}



Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::fmt;
#[allow(unused_imports)]
use std::fmt::Debug;
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let input = get_vec_input();
    let a: i128 = input[0];
    let v: i128 = input[1];
    let input = get_vec_input();
    let b: i128 = input[0];
    let w: i128 = input[1];
    let t: i128 = get_vec_input()[0];
    if (a - b).abs() <= t * (v - w) {
        println!("YES");
    } else {
        println!("NO");
    }
}

#[allow(dead_code)]
fn get_digit(value: i64) -> i64 {
    let mut digit = 0i64;
    let mut value = value;
    while value != 0 {
        value /= 10;
        digit += 1;
    }
    digit
}

#[allow(dead_code)]
fn sum_digit2(value: String) -> u32 {
    return value.chars().fold(0u32, |a, b| a + b.to_digit(10).unwrap());
}

#[allow(dead_code)]
fn sum_digit(value: i64) -> i64 {
    if value < 10 {
        return value;
    }
    return sum_digit(value / 10) + value % 10;
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn get_vec_input<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<T> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    vec
}

#[allow(dead_code)]
fn get_tuple_input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}

#[allow(dead_code)]
fn get_string_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    s.trim().to_string()
}


Measured memory_bytes: 2160
import sys
input = sys.stdin.readline
def main():
    N, M, X = map(int, input().split())
    ans = 10 ** 9
    C_list = []
    A_list = []
    for _ in range(N):
        CA = list(map(int, input().split()))
        C_list.append(CA[0])
        A_list.append(CA[1:])
    for bit in range(2**N):
        cost = 0
        A = [0 for _ in range(M)]
        clear = True
        for i in range(N):
            if bit & 1<<i:
                cost += C_list[i]
                for j in range(M):
                    A[j] += A_list[i][j]
        for k in range(M):
            clear = clear and (A[k] >= X)
        if clear:
            ans = min(ans, cost)
    if ans == 10 ** 9:
        ans = -1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 68384
N = int(input())
ps = [int(x) for x in input().split()]

for i in range(N):
    min_n = ps[i]
    index = i
    for j in range(i+1, N):
        if ps[j] < min_n:
            min_n = ps[j]
            index = j

    if index != i:
        tmp = ps[i]
        ps[i] = ps[index]
        ps[index] = tmp
        break
    
sorted_ps = sorted(ps)
if ps == sorted_ps:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define in insert
using namespace std;
int main()
{
	int n;
	cin>>n;
	ll a[n],b[n],c[n];
	for(ll i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
	ll dp[n][3];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(ll i=1;i<n;i++)
	{
	    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
	    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
	    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return 0;
}


Measured memory_bytes: 8272
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pp;

int main() {
    long long N,M;
    cin >> N >> M;

    if(N == 1 && M == 1) cout << 1 << endl;
    else if(N == 1 && M != 1) cout << M - 2 << endl;
    else if(N != 1 && M == 1) cout << N - 2 << endl;
    else cout << (N - 2) * (M - 2) << 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;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  ll n;
  cin >> n;
  set<ll> ans;
  REP(i,n){
    int in;
    cin >> in;
    if(ans.find(in)!=ans.end()) ans.erase(in);
    else ans.insert(in);
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 4864
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'


int32_t main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr), cout.tie(nullptr);

    int x, y; cin >> x >> y;
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 100; j++) {
        bool animal_count = i + j == x;
        bool leg_count = 2 * i + 4 * j == y;
        if (animal_count && leg_count) 
          return cout << "Yes", 0;
      }
    }
    cout << "No" << endl;
}

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

struct dice {
	int back, bottom, front, left, right, top;
};

class Dice {
	dice a;

public:
	Dice(dice& newA) : a(newA) {}

	dice get() {
		return a;
	}

	void move(string& b) {
		for (char& i : b) {
			dice tmp;
			if (i == 'E') {
				tmp.back = a.back;
				tmp.bottom = a.right;
				tmp.front = a.front;
				tmp.left = a.bottom;
				tmp.right = a.top;
				tmp.top = a.left;
			}
			else if (i == 'N') {
				tmp.back = a.top;
				tmp.bottom = a.back;
				tmp.front = a.bottom;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.front;
			}
			else if (i == 'S') {
				tmp.back = a.bottom;
				tmp.bottom = a.front;
				tmp.front = a.top;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.back;
			}
			else {
				tmp.back = a.back;
				tmp.bottom = a.left;
				tmp.front = a.front;
				tmp.left = a.top;
				tmp.right = a.bottom;
				tmp.top = a.right;
			}
			a = tmp;
		}
	}
};

int main() {
	dice a;
	cin >> a.top >> a.front >> a.right >> a.left >> a.back >> a.bottom;
	Dice b(a);
	string c;
	cin >> c;
	b.move(c);
	cout << b.get().top << endl;
}


Measured memory_bytes: 3192
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

bool warshall_floyd(vector< vector<long long> >& cost){
    const int v = (int)cost.size();

    constexpr long long INF = 1LL << 61;

    for(int k = 0 ; k < v ; ++k){
        for(int i = 0 ; i < v ; ++i){
            for(int j = 0 ; j < v ; ++j){
                if(cost[i][k] < INF && cost[k][j] < INF){
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
    }

    for(int i = 0 ; i < v ; ++i){
        if(cost[i][i] < 0LL){
            return false;
        }
    }

    return true;
}

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

    int n, m;
    lint l;
    cin >> n >> m >> l;

    vector< vector<lint> > cost(n, vector<lint>(n, LLINF));
    rep(i, m){
        int a, b;
        lint c;
        cin >> a >> b >> c;
        if(c <= l){
            chmin(cost[--a][--b], c);
            chmin(cost[b][a], c);
        }
    }

    warshall_floyd(cost);

    vector< vector<lint> > cost2(n, vector<lint>(n, LLINF));
    rep(i, n){
        rep(j, n){
            if(cost[i][j] <= l){
                cost2[i][j] = 1;
            }
        }
    }

    warshall_floyd(cost2);

    int q;
    cin >> q;

    vector<lint> ans;
    while(q--){
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        if(cost2[s][t] < LLINF){
            ans.emplace_back(cost2[s][t] - 1);
        }else{
            ans.emplace_back(-1LL);
        }
    }

    for(auto x : ans){
        cout << x << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 2936
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	double a, b, x;
	cin >> a >> b >> x;

	if (x < a*a*b / 2) {

		double c = x / a * 2 / b;
		cout << setprecision(8) << atan((double)b / c) / (2 * acos(-1)) * 360;

	}
	else {

		double c = (x / a * 2 / a) - b;
		cout << setprecision(8) << atan((double)(b-c) / a) / (2 * acos(-1)) * 360;

	}

	

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

int main() {

	Int n, a, b;
	cin >> n >> a >> b;
	Int ans = min(b, a * n);

	cout << ans << endl;

}

Measured memory_bytes: 256
from collections import Counter

def SUMCHK():
    N = int(input())
    S = input()

    C=Counter(S)
    r = C['R']
    g = C['G']
    b = C['B']


    cnt = r * g * b

    for i in range(0,N-2):
        for j in range(i,N-1):
            k = j + j - i
            if k < N:
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    cnt -= 1

    print(cnt)

SUMCHK()


Measured memory_bytes: 9484
#include<iostream>
#include<string>
using namespace std;
int main() {
	int m, g;
	int n;
	while (cin >> n&&n != 0) {
		m = 0;
		g = 0;
		string a;
		bool l = true;
		for (int i = 0; i < n; i++) {
			cin >> a;
			if (a == "A") {
				m++;
			}
			else if(a=="Un"){
				m--;
			}
			if (m<0) {
				l = false;
			}
		}
		if (l&&m==0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 3160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(helper(a, b));
        sc.close();
    }

    public static int helper(int a, int b) {
        if (a < b) return helper(b, a);
        if (a - b > 1) return 2 * a - 1;
        else return a + b;
    }
}

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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	vector<int> contest(3);
	rep(i, N) {
		int P;
		cin >> P;
		if (P <= A) contest.at(0)++;
		else if (A < P && P <= B) contest.at(1)++;
		else contest.at(2)++;
	}
	cout << *min_element(contest.begin(),contest.end()) << endl;
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> l(n);
  for (int i=0; i<n; i++) {cin >> l.at(i);}
  int count = 0;

  for (int i=0; i<n-1; i++) {
    int minj = i;
    for (int j=i; j<n; j++) {
      if (l.at(minj) > l.at(j)) {
        minj = j;
      }
    }
    if (minj != i)  count++;
    swap(l.at(minj), l.at(i));
  }
  for (int i=0; i<n-1; i++) {
    cout << l.at(i) << " ";
  }
  cout << l.at(n-1) << endl;
  cout << count << endl;
}



Measured memory_bytes: 3120
#include <iostream>
#include <vector>

int main() {

    /*
     * On each day, we can do one of three things. but which do we do?
     * Let dp[i] represent the total happiness so far.
     * On any given day, we could have done one of three things yesterday.
     *     std::max(
     *         dp[i-1][0] + max(hap[i][1], hap[i][2]),
     *         dp[i-1][1] + max(hap[i][0], hap[i][2]),
     *         dp[i-1][2] + max(hap[i][0], hap[i][1]),
     *     )
     *
     * Initialize dp[0][i] = hap[0][i]
     */

    int n;
    std::cin >> n;
    std::vector<std::vector<int>> hap(n, std::vector<int>(3));
    std::vector<std::vector<int>> dp(n, std::vector<int>(3));

    for (int i = 0; i < n; i++) {
        std::cin >> hap[i][0];
        std::cin >> hap[i][1];
        std::cin >> hap[i][2];
    }

    dp[0][0] = hap[0][0];
    dp[0][1] = hap[0][1];
    dp[0][2] = hap[0][2];

    for (int i = 1; i < n; i++) {
        for (int a = 0; a < 3; a++) {
            int actA = 0;
            int actB = 2;
            if (a == 0) actA = 1;
            if (a == 2) actB = 1;

            dp[i][a] = std::max(dp[i-1][actA], dp[i-1][actB]) + hap[i][a];
        }
    }

    int best = std::max(dp[n-1][0], dp[n-1][1]);
    best = std::max(best, dp[n-1][2]);

    std::cout << best;

    return 0;
}



Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long l;
int main()
{
    int n,a=0,w=0,t=0,r=0;
    cin>>n;
    for(int i = 0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s == "AC")
            a++;
        else if(s == "WA")
            w++;
        else if(s == "TLE")
            t++;
        else if(s == "RE")
            r++;
    }
    cout<<"AC"<<" "<<"x"<<" "<<a<<'\n'<<"WA"<<" "<<"x"<<" "<<w<<'\n'<<"TLE"<<" "<<"x"<<" "<<t<<'\n'<<"RE"<<" "<<"x"<<" "<<r;
    return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  string s[128];
  string M;
  for (int i = 0; i < N; i++) cin >> s[i];
  sort(s, s + N);
  for (int i = 0; i < N; i++) cout << s[i];
  cout << endl;
  return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct F{
    int U;
    int N;
    vector<vint>A;
    vint R,C;
    vpint la;
    int dgn,dgn2;
    int sc;
    void init(int n,int u,vector<vint>a){
        N=n;U=u;A=a;
        R=C=vint(N);
        la=vpint(1000000,{-1,-1});
        rep(i,N)rep(j,N){
            a[i][j]--;
            la[a[i][j]]={i,j};
        }
        sc=dgn=dgn2=0;
    }
    void add(int n){
        n--;
        if(la[n].fi==-1)return;
        int y,x;
        tie(y,x)=la[n];
        if(++R[y]==N)sc++;
        if(++C[x]==N)sc++;
        if(y==x&&(++dgn==N))sc++;
        if(N-1-y==x&&(++dgn2==N))sc++;
    }
    bool ok(){
        if(N==1)return min(1ll,sc)>=U;
        return sc>=U;
    }
};

signed main(){
    int N,u,v,m;
    cin>>N>>u>>v>>m;
    vector<vint>A(N,vint(N));
    rep(i,N)rep(j,N)cin>>A[i][j];

    F usa;usa.init(N,u,A);
    rep(i,N)rep(j,N)cin>>A[i][j];
    F neko;neko.init(N,v,A);

    vint qs(m);
    rep(i,m)cin>>qs[i];
    rep(i,m){
        usa.add(qs[i]);
        neko.add(qs[i]);
        if(usa.ok()&&neko.ok()){
            cout<<"DRAW"<<endl;
            return 0;
        }
        if(usa.ok()){
            cout<<"USAGI"<<endl;
            return 0;
        }
        if(neko.ok()){
            cout<<"NEKO"<<endl;
            return 0;
        }
    }
    cout<<"DRAW"<<endl;
    return 0;
}

Measured memory_bytes: 38592
/*  ex3_2
    yy8332  */
 
#include <stdio.h>
 
int main(void){
  int number;
 
  //入力受け取り
  scanf("%d", &number);
 
  //下一桁が2,4,5,7,9の場合
  switch(number % 10){
    case 2: case 4: case 5: case 7: case 9:
      printf("hon");
      break;
    //下一桁が0,1,6,8の場合
    case 0: case 1: case 6: case 8:
      printf("pon");
      break;
    //下一桁が3の場合
    case 3:
      printf("bon");
      break;
  }
  return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
              
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
//#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

using namespace std;

const int maxn = (int) 2e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 

#define inf mod

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        


int n, a[maxn][3], dp[maxn][3];                                      
int main () {
  cin >> n;
  forn(i, 1, n){
    forn(j, 0, 2)
      cin >> a[i][j], dp[i][j] = -inf;
  }
  forn(i, 1, n){
    forn(j, 0, 2)
      forn(lst, 0, 2)
        if(j != lst)
          dp[i][j] = max(dp[i][j], dp[i - 1][lst] + a[i][j]); 
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}


Measured memory_bytes: 3456
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/


int main() {

 // freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);

  int sum=0, num;
  rep(i,5){cin>>num;sum+=num;}
  cout<<15-sum<<endl;

  return 0;
}


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

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

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}


int main() {
    int H,W; cin >> H >> W;
    V<string> S(H); 
    REP(i,H) cin >> S[i];
    V<V<int>> a(H,V<int>(W,-1));
    REP(i,H) REP(j,W) if(S[i][j] == '#') a[i][j] = 0;
    queue<P<int,int>> q;
    REP(i,H) REP(j,W) if(a[i][j] == 0) q.push({i,j});
    while(q.size()){
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        if(y+1<H&&a[y+1][x] == -1){
            a[y+1][x] = a[y][x] + 1;
            q.push({y+1,x});
        }
        if(0 <= y-1&&a[y-1][x] == -1){
            a[y-1][x] = a[y][x] + 1;
            q.push({y-1,x});
        }
        if(x+1<W&&a[y][x+1] == -1){
            a[y][x+1] = a[y][x] + 1;
            q.push({y,x+1});
        }
        if(0 <= x-1&&a[y][x - 1] == -1){
            a[y][x-1] = a[y][x] + 1;
            q.push({y,x-1});
        }        
    }
    int ans = 0;
    for(int i = 0; i < H; ++i){
        REP(j,W){
            chmax(ans,a[i][j]);
        }
    
    }
    cout << ans << endl;

  
	return 0;
}


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

const int INF = 1e8;

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

  for(int query = 0; query<Q; query++){
    string S, T; cin >> S >> T;

    //dp[i][j]: S[i],T[j]まででの最長共通部分列
    vector<vector<int>> dp(1010, vector<int>(1010, 0));
    
    for(int i=0; i<S.length(); i++){
      for(int j=0; j<T.length(); j++){
        if(S[i] == T[j]){
          dp[i+1][j+1] = dp[i][j]+1;
        } else {
          dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
      }
    }
    cout << dp[S.length()][T.length()] << endl;
  }
}


Measured memory_bytes: 6852
h, f = {}, {}

gets.chomp.split.each { |w| 
  h[w] = f[w] = 0 if h[w].nil?
  h[w] += 1
  f[w] = w.length
}

def m(h) h.max { |a, b| a[1] <=> b[1] }.shift end 
puts "#{m(h)} #{m(f)}"

Measured memory_bytes: 2332
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  cin>>n;
  int l[2 * n];
  rep(i, 2 * n) cin>>l[i];
  sort(l, l + 2 * n);
  int ans = 0;
  
  for(int i = 0; i < 2 * n; i += 2)
  {
    ans += l[i];
  }
  cout << ans << endl;

  return 0;
}


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


int main() {
  int n;
  cin >> n;
 
 
  vector<vector<int>> x(n,vector<int>(10));
  rep(i,n) {
    rep(j,10){
      cin >> x.at(i).at(j);
    }
  }
  vector<vector<int>> p(n,vector<int>(11));
  rep(i,n) {
    rep(j,11){
      cin >> p.at(i).at(j);
    }
  }
  int ans=-1001001001;
  for (int tmp = 1; tmp < (1 << 10); tmp++) {
    bitset<10> s(tmp);
    vector<int>co(n);
    rep(i,10){
      if(s.test(i)){
        rep(j,n){
          if(x.at(j).at(i)==1){
            co.at(j)++;
          }
        }
      }
    }
    int now=0;
    rep(i,n){
      now+=p.at(i).at(co.at(i));
    }
    ans=max(ans,now);       
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

# 一番西がリーダーの時
l = 0
# 東を向いている人の数
r = S[1:].count('E')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'W':  # 元リーダーの人が西向きの時
        l += 1
    if S[i] == 'E':  # 現リーダーが東向きの時
        r -= 1
    cnt = l+r
    ans = min(cnt, ans)  # 向きを変える必要のある人数
print(ans)

Measured memory_bytes: 8056
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int X, t; cin >> X >> t;

    cout << max(X - t, 0) << endl;
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}

const int maxn = 1e6 + 5;

void spa(vector<vector<pair<ll,int>>> g, vector<ll>& dist, vector<ll>& ways, int src) {
    int n = g.size();
    dist.assign(n, inf);
    dist[src] = 0;
    ways.assign(n, 0);
    ways[src] = 1;

    priority_queue<pair<ll,int>> pq;
    pq.emplace(0, src);

    while (pq.size()) {
	auto cur = pq.top();
	pq.pop();
	int at = cur.second;
	ll walk = -cur.first;
	if (walk > dist[at]) {
	    continue;
	}
	for (auto ed: g[at]) {
	    ll wei = ed.first;
	    int to = ed.second;
	    if (walk+wei < dist[to]) {
		ways[to] = ways[at];
		dist[to] = walk+wei;
		pq.emplace(-dist[to], to);
	    } else if (walk+wei == dist[to]) {
		add(ways[to], ways[at]);
	    }
	}
    }
    
}


int n, m, s, t;
vector<vector<pair<ll,int>>> g;
vector<ll> sdist, tdist, sways, tways;

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

    cin>>n>>m>>s>>t;
    --s; --t;
    assert(s != t);
    
    g.resize(n);
    sdist.resize(n);
    sways.resize(n);
    tdist.resize(n);
    tways.resize(n);

    for (int i=0; i<m; i++) {
	int u,v,d; cin>>u>>v>>d;
	--u; --v;
	g[u].push_back({d,v});
	g[v].push_back({d,u});
    }

    spa(g, sdist, sways, s);
    spa(g, tdist, tways, t);

    assert(sdist[t] == tdist[s]);
    assert(sways[t] == tways[s]);

    
    ll dist = sdist[t];
    ll ways = sways[t]*sways[t]%mod;


    for (int i=0; i<n; i++) {
	if (i==s || i==t) {
	    continue;
	}
	
	// there exists a shortest path that goes through node i
	if (sdist[i]==dist/2 && tdist[i]==dist/2 && sdist[i]+tdist[i]==dist) {
	    ll paths = sways[i]*tways[i]%mod;
	    ll pairs = paths*paths%mod;
	    //cout<<i<<": "<<paths<<endl;
	    ways -= pairs;
	    ways %= mod;
	}
    }


    for (int u=0; u<n; u++) {
	for (auto ed: g[u]) {
	    int v = ed.second;
	    ll wei = ed.first;
	    if (sdist[u]*2<dist && tdist[v]*2<dist && sdist[u]+wei+tdist[v]==dist) {
		// there exists a shortest path via u-v edge
		ll paths = sways[u]*tways[v]%mod;
		ll pairs = paths*paths%mod;
		ways -= pairs;
		ways %= mod;
	    }
	}
    }

    ways %= mod;
    ways += mod;
    ways %= mod;
    cout<<ways<<endl;
    
    return 0;
}


Measured memory_bytes: 31428
N, X, Y = map(int, input().split(' '))
dist = [[0 for _ in range(N + 10)] for _ in range(N + 10)]
dist[X][Y] = 1
res = [0 for i in range(N + 10)]
for i in range(1, N):
  for j in range(i + 1, N + 1):
    dist[i][j] = min(j - i, abs(j - X) + 1 + abs(i - Y), abs(j - Y) + 1 + abs(i - X))
    res[dist[i][j]] += 1
for i in range(1, N):
  print(res[i])

Measured memory_bytes: 83420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < input.length; i++) {
			a[i] = Integer.parseInt(input[i]);
		}
		
		int ans = solve(a);
		
		System.out.println(ans);
	}

	private static int solve(int[] a) {
		
		int[] dp = new int[a.length];
		
		Arrays.fill(dp, Integer.MAX_VALUE);
		
		dp[0] = 0;
		
		for (int i = 0; i < dp.length; i++) {
			
			if((i+1)<a.length)
				dp[i+1] = Math.min(dp[i+1],dp[i]+ Math.abs(a[i]-a[i+1]));
			
			if((i+2)<a.length)
				dp[i+2] = Math.min(dp[i+2],dp[i]+ Math.abs(a[i]-a[i+2]));
			
		}
		
		return dp[a.length-1];
	}
}

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

using namespace std;

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

	vector<long> a(n + 1);
	for (int i = 0; i < n + 1; i++)
	{
		cin >> a.at(i);
	}

	vector<long> b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> b.at(i);
	}

	long ans = 0;
	for (int i = 0; i < n; i++)
	{
		int left = min(a.at(i), b.at(i));
		a.at(i) -= left;
		b.at(i) -= left;
		ans += left;

		int right = min(a.at(i + 1), b.at(i));
		a.at(i + 1) -= right;
		b.at(i) -= right;
		ans += right;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
N = gets.to_i
T, A = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)

min = 10 ** 9
ans = 0

H.each.with_index {|h, i|
  t = T - h * 0.006
  if (A - t).abs < min
    min = (A - t).abs
    ans = i + 1
  end
}

puts ans

Measured memory_bytes: 14320
from math import ceil
h,n = map(int,input().split())

inf = float('INF')
dp = [inf for i in range(h+1)]
dp[0] = 0
for _ in range(n):
    a,b = map(int,input().split())
    for i in range(h+1):
        idx = i-a if i >= a else 0
        if i >= a and dp[i] > dp[idx] + b:
            dp[i] = dp[i-a] + b
        elif i <= a and b < dp[i]:
            dp[i] = b
print(dp[h])
# print(dp)


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

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int K, A, B;
    cin >> K >> A >> B;
    for (int n = A; n <= B; n++) {
        if (n % K == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
using namespace std;
//---------------------------------------
int max_profit(vector<int> vec);
//---------------------------------------

int main(void)
{
	int num;
	vector<int> num_all;
	
	cin >> num;
	
	for(int i = 0; i < num; i++){
		int n;
		cin >> n;
		num_all.push_back(n);
	}
	cout << max_profit(num_all) << endl;
	
	return 0;
}
//--------------------------------------------
int max_profit(vector<int> vec)
{
	int minv = vec[0];
	int maxv = vec[1] - vec[0];
	
	for(int j = 1; j < vec.size(); j++){
		if((vec[j] - minv) > maxv){
			maxv = vec[j] - minv;
		}
		if((vec[j] < minv)){  //????????????????????????
			minv = vec[j]; 
		}
	}
	return maxv;
}
/*time error
int max_profit(vector<int> vec)
{
	int max = vec[1] - vec[0]; //???????????????????????\????????????
	
	for(int i = vec.size() - 1; i > 0; i--){
		for(int j = 0; j < i; j++){
			int num = vec[i] - vec[j];
			if(max < num){
				max = num;
			}
		}
	}
	return max;
}
*/

Measured memory_bytes: 4580
A = []
 
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
 
for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit()
 
 
 
print('No')

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

typedef long long ll;

int N, MAX_N = 200000, INF = 1e9 + 1;
vector<int> a(MAX_N), ans(MAX_N), dp(MAX_N + 1, INF);
vector<vector<int>> edge(MAX_N);
vector<bool> done(MAX_N, false);

void check(int x) {
    done[x] = true;
    int p = lower_bound(dp.begin(), dp.end(), a[x]) - dp.begin();
    int b = dp[p];
    dp[p] = a[x];
    ans[x] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    int n = edge[x].size();
    rep(i, n) {
        int y = edge[x][i];
        if (done[y]) continue;
        check(y);
    }
    dp[p] = b; 
}

int main() {
    int u, v;
    cin >> N;
    rep(i, N) cin >> a[i];
    rep(i, N - 1) {
        cin >> u >> v;
        u--;
        v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    check(0);
    rep(i, N) {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 27860
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
from scipy.misc import comb # comb(n, r, exact=True)
# import numpy as np
# import heapq
# import array


def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = [''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]
  
    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >= 2:
            count += comb(c, 2, exact=True)

    print(count)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    if(t == 0) {
        cout << "1\n";
    }
    else {
        cout << "0\n";
    }
    return 0;
}

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



int main(){
    int m,n;
    while(cin>>m,m){
        cin>>n;
        vector<bool> c(7368792,false);
        int s=1;
        
        while(s*m<7368792){
        
            c.at(s*m)=true;
            s++;
        }
        int t=m;
        for(int i=0;i<n-1;i++){
            int j=t;
            while(c.at(j)==true){
                j++;
            }
            t=j;
            s=1;
            while(s*j<7368792){
                c.at(s*j)=true;
                s++;
            }
        }
        int j=m;
        while(c.at(j)==true){
            j++;
        }
       /* for(int i=0;i<20;i++){
            cout<<c.at(i)<<endl;
            }
            cout<<endl;*/
        cout<<j<<endl;
   }
   
}


Measured memory_bytes: 3912
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define fi first
#define fs first
#define se second
#define sc second
//#define int long long
#define ll long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;

string s;
int num[4];
int id;

int dfs() {
    if (s[id] == '(') {
        id++;
        int num1 = dfs();
        char ope = s[id];
        id++;
        int num2 = dfs();
        id++;
        if (ope == '*') return num1 & num2;
        else return num1 ^ num2;
    }
    else if (s[id] == '-') {
        id++;
        int num = dfs();
        return (1 ^ num);
    }
    else {
        if (s[id] == '0') {
            id++; return 0;
        }
        if (s[id] == '1') {
            id++; return 1;
        }
        return num[s[id++] - 'a'];
    }
}

map<int,int> mp;
vec len[17];

void solve() {
    int n = (int)s.length();
    int state = 0;
    int cnt = 0;
    rep(a, 0, 2) rep(b, 0, 2) rep(c, 0, 2) rep(d, 0, 2) {
        id = 0;
        num[0] = a, num[1] = b, num[2] = c, num[3] = d;
        state += (1 << cnt) * dfs();
        //cout << ((state & (1 << cnt)) > 0) << " ";
        cnt++;
    }
    //cout << state << endl;
    cout << mp[state] << endl;
}

int main() {
    len[1].emplace_back(0b0000000000000000); //0
    len[1].emplace_back(0b1111111111111111); //1
    len[1].emplace_back(0b1111111100000000); //a
    len[1].emplace_back(0b1111000011110000); //b
    len[1].emplace_back(0b1100110011001100); //c
    len[1].emplace_back(0b1010101010101010); //d
    REP(i, 6) mp[len[1][i]] = 1;

    FOR(i, 2, 17) {
        //-
        for (int b : len[i - 1]) {
            int tmp = ((1 << 16) - 1) ^ b;
            if (mp.count(tmp)) continue;
            mp[tmp] = i;
            len[i].emplace_back(tmp);
        }
        // ^
        FOR(j, 1, i-3) {
            int k = i - 3 - j;
            for (int b : len[j]) {
                for (int c : len[k]) {
                    int tmp = b & c;
                    //cout << tmp << endl;
                    if (!mp.count(tmp)) {
                        mp[tmp] = i;
                        len[i].emplace_back(tmp);
                    }

                    tmp = b ^ c;
                    if (mp.count(tmp)) continue;
                    mp[tmp] = i;
                    len[i].emplace_back(tmp);
                }
            }
        }
    }

    while (cin >> s) {
        if (s == ".") break;
        solve();
    }
}


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


#define AMARI (1000000007)

int main(){
    int n,m;
    cin>>n>>m;
    unsigned long long a[100000];
    unsigned long long fib[100000];

    for (int i = 0; i < m; i++)
    {
        cin>>a[i];
    }
    for (int i = 1; i < m; i++)
    {
        if(a[i]-a[i-1]==1){
            cout<<"0"<<endl;
            return 0;
        }
    }
    
    fib[0] = 1;
    fib[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        fib[i]=fib[i-1]+fib[i-2];
        fib[i] %= AMARI;
            // cout<<i<<" "<<fib[i]<<endl;
    }
    
    unsigned long long ans = 1;
    
    if(m==0){
        ans = fib[n];
        ans %= AMARI;
    }else{
        ans = fib[a[0]-1];
        for (int i = 1; i < m; i++)
        {
            ans *= fib[a[i]-a[i-1]-2];
            ans %= AMARI;
        }
        ans *= fib[n-a[m-1]-1];
        ans %= AMARI;
    }
    
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll isused[500005];
vector<ll>adj[500005];
deque<ll>res;
ll GCD[500][500];
int main() {
    fastread;
    ll t, n, i, j, k, l, m;
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            GCD[i][j]=__gcd(i,j);
        }
    }
    ll sum=0;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                sum+=GCD[i][GCD[j][k]];
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 16160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
 
typedef long long ll;

// v[i] := 桁数が(i+1)の列の合計文字数.
vector<ll> v;

// 10^x を返す.
ll pow10_(ll x){
	ll res = 1;
	for(ll i = 0 ; i < x ; i++ ) res *= 10;
	return res;
}

// long long => string の変換.
string i_to_s(ll n){
	string s;
	do{
		s.push_back( (n % 10) + '0' );
		n /= 10;
	}while( n != 0 );
	reverse(s.begin(), s.end());
	return s;
}

// k を超えない最大の (d+1) * x を求める.
ll search(ll k, ll d, ll &x){
	ll low = 0, high = 1e+18;
	while( 1 < high - low ){
		ll mid = (low + high) / 2;
		ll n = (d + 1) * mid;
		
		if( n < k ){
			low = mid;
		}else{
			high = mid;
		}
	}
	
	ll a = (d + 1) * low, b = (d + 1) * high;
	if( b <= k ){
		x = high;
		return b;
	}
	x = low;
	return a;
}

// 位置 pos の文字を返す.
char solve(ll pos){ 
	for(int i = 0 ; i < v.size() ; i++ ){
		if( 0 <= pos - v[i] ){ // 次の桁数にする.
			pos -= v[i];
		}else{ // 桁数が(i+1)のどこかをposが指している.
			ll x;
			pos -= search(pos, i, x);
			x = x + pow10_(i);
			string s = i_to_s(x);
			// s(i+1桁の数字) のどこかを pos が指している.
			for(int j = 0 ; j < s.size() ; j++ ){
				if( pos == 0 ){
					return s[j];
				}
				pos--;
			}
		}
	}
	return 0;
}

int main(){
	// 各桁数 i について合計の文字数を求めておく.
	for(ll i = 1, n = 9; i <= 19 ; i++, n*= 10 ){
		v.push_back(n * i);
	}
	
	ll N, K;
	while( cin >> N >> K, N || K ){
		// 位置 (N-1) から K 文字出力する.
		for(int i = N - 1 ; i < N + K - 1 ; i++ ){
			cout << solve(i);
		}
		cout << endl;
	}
}

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

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[] cnt = new int[M];
        for (int i = 0; i < N; i++) {
            int K = Integer.parseInt(scanner.next());
            for (int j = 0; j < K; j++) {
                cnt[Integer.parseInt(scanner.next()) - 1]++;
            }
        }
        
        int ans = 0;
        for (int i = 0; i < M; i++) {
            if (cnt[i] == N)
                ans++;
        }
        System.out.println(ans);
    }

}



Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
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; }

// ****************************************CODE***************************************//


ll n, k;
ll h[110000];
ll dp[110000];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 110000; i++) dp[i] = inf;

    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if(i>1) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1920