akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

signed main() {
	int H, W;
	cin >> H >> W;

	int c[10][10];
	rep(i, 10) rep(j, 10) {
		cin >> c[i][j];
	}

	rep(k, 10) rep(i, 10) rep(j, 10)
		c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

	int A[210][210];
	rep(y, H) rep(x, W) cin >> A[y][x];

	int ret = 0;
	rep(y, H) rep(x, W) {
		if (A[y][x] == -1) continue;
		ret += c[A[y][x]][1];
	}
	cout << ret << endl;
}


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

int main(){
  int k,a,b;
  cin >> k >> a >>b;
  int c,d;
  c = b/k;
  d = c * k;
  if(a<=d&&d<=b) cout << "OK";
  if(d<a||b<d) cout <<"NG";
}


Measured memory_bytes: 3620
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

const INF: usize = 1_000_000_000_000_000;

fn solve() {
    let (n, ma, mb) = get!(usize, usize, usize);
    let abc = get!(usize, usize, usize; n);

    let mut dp = vec![vec![vec![INF; 401]; 401]; n+1];
    dp[0][0][0] = 0;
    for i in 0..n {
        for a in 0..401 {
            for b in 0..401 {
                dp[i+1][a][b] = if abc[i].0 > a || abc[i].1 > b {
                    dp[i][a][b]
                } else {
                    min!(dp[i][a][b], dp[i][a-abc[i].0][b-abc[i].1]+abc[i].2)
                };
            }
        }
    }
    let mut mn = INF;
    for a in 0..401 {
        for b in 0..401 {
            if a == 0 && b == 0 {
                continue;
            }
            if ma*b == mb*a {
                mn = min!(mn, dp[n][a][b]);
            }
        }
    }
    if mn == INF {
        println!("-1");
        return;
    }
    println!("{}", mn);
}


Measured memory_bytes: 67964
// agrawal117
//chahatagrawal117
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int ll;
const  ll mod=1000000007;
const int MAX=1000000+9;
int main()
{
    double a, b, c;
    cin >> a >> b >> c;
    cout << ceil(c/max(a, b));
}

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

int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[2] == s[3])
    {
        if (s[1] != s[2])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (s[0] == s[2] && s[1] == s[3])
    {
        if (s[1] != s[2])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (s[0] == s[3] && s[1] == s[2])
    {
        if (s[0] != s[1])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m;cin>>n>>m;
  string s(n,'0');
  s[0]=n==1?'0':'1';
  map<int,char> cond;
  rep(i,m){
    int si;cin>>si;
    char ci;cin>>ci;
    if(cond.find(si)!=cond.end()&&cond[si]!=ci){
      s="-1";
      break;
    }else if(n>1&&si==1&&ci=='0'){
      s="-1";
      break;      
    }
    cond[si]=ci;
    s[si-1]=ci;
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
int main(){ 
	int n,m,k;
	cin>>n>>m>>k;
	char a[n][m];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	int ans=0;
	for(int i=0;i<1<<n;i++){
		for(int j=0;j<1<<m;j++){
			int count=0;
			for(int k=0;k<n;k++){
				if((1<<k)&i)
					continue;
				for(int l=0;l<m;l++){
					if((1<<l)&j)
						continue;
					if(a[k][l]=='#')
						count++;
				}
			}
			if(count==k)
				ans++;
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3552
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int l, r;
  readf("%s %s\n", &l, &r);
  int[int] cnt;
  foreach (i; l..min(r+1, l+2019)) {
    cnt[i%2019]++;
  }
  auto keys = cnt.keys;
  sort(keys);
  auto res = int.max;
  foreach (i; 0..keys.length) {
    foreach (j; i+1..keys.length) {
      res = min(res, (keys[i] * keys[j]) % 2019);
    }
  }
  res.writeln;
}


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

int mod = 1;

struct ModInt {
  int val;
  int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  ModInt(int v = 0) : val(trim(v % mod)) {}
  ModInt(long long v) : val(trim(v % mod)) {}
  ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  ModInt operator*(const ModInt &oth) const { return 1LL * val * oth.val % mod; }
  ModInt operator/(const ModInt &oth) const {
    function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
      if (b == 0) return trim(x);
      return modinv(b, a - a / b * b, y, x - a / b * y);
    };
    return *this * modinv(oth.val, mod, 1, 0);
  }
  bool operator==(const ModInt &oth) const { return val == oth.val; }
  ModInt operator-() const { return trim(mod - val); }
  template<typename T> ModInt pow(T pw) {
    bool sgn = false;
    if (pw < 0) pw = -pw, sgn = true;
    ModInt ans = 1;
    for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
      if (pw&1) ans = ans * cur;
    }
    return sgn ? ModInt{1} / ans : ans;
  }
};

using mint = ModInt;

int n;
vector<int> g[1<<17];

mint dp_sb[1<<17], dp_all[1<<17];

void dfs_sb(int u, int p) {
  mint& ans = dp_sb[u] = 1;
  auto it = find(g[u].begin(), g[u].end(), p);
  if (it != g[u].end()) g[u].erase(it);
  for (int v : g[u]) if (v != p) {
    dfs_sb(v, u);
    ans = ans * (dp_sb[v] + mint(1));
  }
}


void dfs_all(int u, mint from_pa) {
  dp_all[u] = dp_sb[u] * (from_pa + 1);
  int n = g[u].size();
  vector<mint> fprod(n + 1, mint(1));
  vector<mint> bprod(n + 1, mint(1));
  for (int i = 0; i < n; ++i) {
    fprod[i + 1] = fprod[i] * (dp_sb[g[u][i]] + mint(1));
  }
  for (int i = n - 1; i >= 0; --i) {
    bprod[i] = bprod[i + 1] * (dp_sb[g[u][i]] + mint(1));
  }
  assert(bprod[0] == fprod[n]);
  dp_all[u] = (from_pa + mint(1)) * fprod[n];
  for (int i = 0; i < n; ++i) {
    dfs_all(g[u][i], (from_pa + mint(1)) * fprod[i] * bprod[i + 1]); 
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> n >> mod;
  for (int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs_sb(0, 0);
  dfs_all(0, 0);
  for (int i = 0; i < n; ++i) {
    cout << dp_all[i].val << '\n';
  }
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define zcin(type, a) type a; cin >> a;
#define zcout(a, sep1, b, sep2) cout << a << sep1 << b << sep2;
#define zfor(i, b, n) for (int i = b; i < n; ++i)
#define pb push_back

const int MX = 1e5 + 5;
using namespace std;

int main()
{
	#ifdef ME
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	int n; cin >> n;
	int dp[MX][3];   //total point of happiness, (day i, by doing activity j) 
	int abc[MX][3];

	for (int i = 1; i <= n; ++i)
		cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < 3; j++)
		{
			int ans = 0;
			for (int l = 0; l < 3; ++l)
			{
				if (l == j)
					continue;
				ans = max(ans, dp[i-1][l] + abc[i][l]);
			}
			dp[i][j] = max(dp[i][j], ans);
			//printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
		}
		//printf("\n\n");
	}

	cout << max({dp[n][0], dp[n][1], dp[n][2]});

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
vector<int> c[26];
class fenwick
{
	// 1-based indexing...
	public:
		fenwick(int n)
		{
			this->n = n;
			v.resize(n+1,0);
		}
	private:
		int n;
		std::vector<int> v;
	public:
		void update(int i,int x)
		{
			while(i<=n){
				v[i] += x;
				i += (i&(-i));
			}
		}
		int query(int i)
		{
			int sum = 0;
			while(i>0){
				sum += v[i];
				i -= (i&(-i));
			}
			return sum;
		}
};
int main()
{
	string s; cin >> s;
	int N = s.size();
	vector<int> v(N);
	vector< pair <int,int> > vp;
	for(int i = 0; i < s.size(); ++i) {
		c[(char)s[i] - 'a'].push_back(i);
	}
	bool flag = false;
	int idx;
	for(int i = 0; i < 26; ++i) {
		if(c[i].size() & 1) {
			if(!flag) flag = true, idx = i;
		        else { printf("-1\n"); return 0; }	
		}
	}
	if(flag) {
		v[N/2] = c[idx][(c[idx].size() - 1)/2];
		c[idx].erase(c[idx].begin() + (c[idx].size() - 1) / 2);
	}
	int s1 = 0, e1 = N - 1;
	for(int i = 0 ;i < 26; ++i) {
			for(int j = 0; j < c[i].size() / 2; ++j)  {
				vp.push_back(make_pair(c[i][j],c[i][c[i].size() - 1 - j]));
			}
	}
	sort(vp.begin(),vp.end());
	for(int i = 0; i < vp.size(); i++) v[s1++] = vp[i].first , v[e1--] = vp[i].second;
	for(int i = 0; i < N; i++ ) v[i] += 1; 
	fenwick f(N);
	long long ans = 0;
	for(int i = N - 1; i >=0 ; --i) {
		ans += (long long)f.query(v[i]);
		f.update(v[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> left(n + 1, 0);
    vector<int> right(n + 1, 0);
    for (int i = 0; i < n; i++) left[i + 1] = gcd(left[i], a[i]);
    for (int i = n; i > 0; i--) right[i - 1] = gcd(right[i], a[i - 1]);
    int ans = 1;
    for (int i = 0; i < n; i++) ans = max(ans, gcd(left[i], right[i + 1]));
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 10;

int n, a[N], b[N];

bool check(int v){
	for(int i=1; i<2*n; i++)
		if(a[i] >= v)b[i] = 1; else b[i] = 0;

	int best = -1, mnd = 1e9;
	for(int i=1; i<2*n; i++){
		if(i > 1 && b[i] == b[i - 1]){
			int d = abs(n - i);
			if(d < mnd){
				mnd = d;
				best = i;
			}
		}
		if(i < 2*n-1 && b[i] == b[i + 1]){
			int d = abs(n - i);
			if(d < mnd){
				mnd = d;
				best = i;
			}
		}
	}

	if(best == -1)
		return (b[n] + (n - 1)%2)%2;
	return b[best];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=1; i<2*n; i++)
		cin >> a[i];

	int lo = 0, hi = 2*n;
	while(hi - lo > 1){
		int mid = (lo + hi)/2;
		if(check(mid))lo = mid;
		else hi = mid;
	}

	cout << lo << endl;
}

Measured memory_bytes: 1792
object Main extends App{
  import scala.io.StdIn.readLine;
    val size : (Int, Int) => Int = (x:Int, y:Int) => x*y
    val length : (Int, Int) => Int = (x:Int, y:Int) => (x+y)*2
    val a = readLine().split(' ').map(_.toInt)
    println(size(a(0),a(1)) + " " + length(a(0),a(1)))
}



Measured memory_bytes: 43820
n = int(input())
s = input()
l = [0]
ans = 10**6
for i,si in enumerate(s):
    l.append(l[i]+(si=="W"))
for i in range(n):
    ans = min(ans,l[i]+(n-1-i)-(l[-1]-l[i+1]))
    #print(i,f"W{l[i]} E{(n-1-i)-(l[-1]-l[i+1])}",s[:i],s[i+1:])
print(ans)

Measured memory_bytes: 21400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define pb push_back
#define fst first
#define snd second
#define ALL(cont) cont.begin(), cont.end()
#define mset(a,b) memset(a,b,sizeof(a));
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int MOD = 1e9+7;
const int MAXN = 3000+10;

string cmp;

ll dp[MAXN][MAXN], pr[MAXN][MAXN];

int main()
{
    FIN;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#define endl '\n'
#endif
    int n;cin>>n;
    cin>>cmp;
    dp[1][1] = 1;
    pr[1][1]=1;
    fore(len, 2, n+1){
        vector<ll> pref(n+1);
        fore(b,1,len+1){

            int L,R;
            if(cmp[len-2]=='<'){
                L = 1, R = b-1;
            } else
            {
                L = b, R = len-1;
            }
            
            dp[len][b]=(pr[len-1][R]-pr[len-1][L-1])%MOD;
            // fore(i,L,R+1){
            //     dp[len][b] += dp[len-1][i];
            //     dp[len][b]%=MOD;
            // }
            pr[len][b]=(pr[len][b-1]+dp[len][b])%MOD;
        

        }
    }
    ll ans = 0;
    fore(b,1,n+1){
        ans = (ans+dp[n][b])%MOD;
    }
    cout<<(ans+MOD)%MOD<<endl;
    return 0;
}


Measured memory_bytes: 95940
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    print(S.count("1"))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    d = []

    for i in range(N):
        d.append(int(input()))

    d.sort()
    cnt = 0

    for i in range(N):
        if  i != 0 and d[i] == d[i - 1]:
            cnt = cnt + 1

    print(N - cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define X first
#define Y second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 200000+10;
const int maxm = 200000+10;
const int mod = 1e9+7;
const double eps = 1e-9;
int bit[maxn],tot;
void update(int pos,int val){
    for (;pos<=tot;pos+=lowbit(pos)) bit[pos]+=val;
}
int query(int pos){
    int res=0;
    for (;pos;pos-=lowbit(pos)) res+=bit[pos];
    return res;
}
ll x[maxn],s[maxn];
int get_id(ll val){
    return lower_bound(x+1,x+tot+1,val)-x;
}
int main() {
#ifdef local
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k; cin>>n>>k;
    x[++tot]=0;
    for (int i=1;i<=n;i++){
        int v; cin>>v;
        s[i]=s[i-1]+v;
        x[++tot]=s[i]-1ll*i*k;
    }
    sort(x+1,x+tot+1);
    tot=unique(x+1,x+tot+1)-x-1;
    update(get_id(0),1);
    ll ans=0;
    for (int i=1;i<=n;i++){
        ll tmp=s[i]-1ll*i*k;
        ans+=query(get_id(tmp));
        update(get_id(tmp),1);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 4224
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int a[] =new int[m];
    int b[] =new int[m];
    boolean st[] = new boolean[200000];
    boolean en[] = new boolean[200000];
    boolean ju = false;
    int stn = 0;
    int enn = 0;
    
    for(int i = 0 ; i < m ; ++i){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      if(a[i]==1){
        st[b[i]] = true;
      }
      if(b[i]==n){
        en[a[i]] = true;
      }
    }

    for(int i = 0 ; i < 200000 ; ++i){
      if(st[i] && en[i]){
        ju = true;
        break;
      }

    }
    
    if(ju) System.out.println("POSSIBLE");
    else System.out.println("IMPOSSIBLE");

  }
}

Measured memory_bytes: 62156
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

bool getbit(long long x, int pos) {
    return (x >> pos) & 1;
}

int binketa(long long x) {
    int cnt = 0;
    while (x > 0) {
        x >>= 1;
        cnt++;
    }
    cnt--;
    if (cnt == -1)
        cnt = 0;

    return cnt;
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cin >> b[i];
    }

    int maxketa = binketa(k);

    long long maxx = 0;

    vector<int> onepos;
    for (int i = maxketa; i >= 0; i--) {
        if (getbit(k, i))
            onepos.push_back(i);
    }

    for (auto pos : onepos) {
        long long sumx = 0;
        long long kousei = k & ~((1 << pos) - 1);
        kousei &= ~(1 << pos);
        for (int i = 0; i < n; i++) {
            long long tmp = a[i] & ~((1 << pos) - 1);
            if((tmp | kousei) != kousei)
                continue;

            sumx += b[i];
        }
        maxx = max(maxx, sumx);
    }
    long long sumx = 0;
    for (int i = 0; i < n; i++) {
        if ((k | a[i]) != k)
            continue;
        sumx += b[i];
    }
    maxx = max(maxx, sumx);

    cout << maxx << endl;


    // 一番上がmaxketaの場合
    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static List<String> res=new ArrayList<String>();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),flagp=0,flagq=0;
		String p="",q="";
		for(int i=0;i<n;i++)p+=String.valueOf(sc.nextInt());
		for(int i=0;i<n;i++)q+=String.valueOf(sc.nextInt());

		String s="";
		for(int i=1;i<=n;i++) {
			s+=String.valueOf(i);
		}
		permutation(s,"");
		for(int i=0;i<res.size();i++) {
			if(p.equals(res.get(i)))flagp=i;
			if(q.equals(res.get(i)))flagq=i;
		}
		System.out.println(Math.abs(flagp-flagq));
	}
	public static List<String> permutation(String q, String ans){
        // Base Case
        if(q.length() <= 1) {
            res.add(ans+q);
        }
        // General Case
        else {
            for (int i = 0; i < q.length(); i++) {
                permutation(q.substring(0, i) + q.substring(i + 1),
                        ans + q.charAt(i));
            }
        }
		return res;
    }
}



Measured memory_bytes: 45012
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
bool isprime(int p){
    if(p==1) return false;
    for(int i=2;i<p;i++){
        if(p%i==0) return false;
    }
    return true;
}
int main() {
    int n;
    cin>>n;
    for(int i=11;i<=55555;i++){
        if(isprime(i)==true){
            if(i%5==1){
                cout<<i<<' ';
                n--;
            }
            if(n==0){
                break;
            }
        }
    }
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
using namespace std;

int dp[3005][3005];

int main()
{
    string s1,s2,s3="";
    cin>>s1>>s2;
    int n1=s1.size(), n2=s2.size(),i,j;
    f(i,1,n1+1)
    	f(j,1,n2+1)
    	{
    		if(s1[i-1]==s2[j-1])
    			dp[i][j]=1+dp[i-1][j-1];
    		else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
    	}
    for(i=n1,j=n2;i>0 && j>0;)
   	{
   		if(dp[i][j]!=dp[i-1][j] && dp[i][j]!=dp[i][j-1])
   		{
   			s3+=s1[i-1];
          	i--;j--;
    	}
    	else if(dp[i][j]!=dp[i-1][j] && j>0)
   			j--;
   		else i--;
   	}
    reverse(s3.begin(),s3.end());
    cout<<s3;
}

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

int main(){
    long long n;
    cin >> n;
    long long check = n;
    string ans;
    
    while (check > 0){
        check--;
        ans += (check % 26) + 'a';
        check /= 26;
    }

    reverse(ans.begin(), ans.end());
    

    
    cout << ans << endl;
    
    
    
    
    

}


Measured memory_bytes: 3628
N,Q=map(int, input().split())
s=input()
td=[input().split() for i in range(Q)]

def move(s,td,position):
    p=position
    for spell in td:
        if s[p]==spell[0] and spell[1]=='L':
            p-=1
        elif s[p]==spell[0] and spell[1]=='R':
            p+=1
        if p<0 or p>=N: break
    return p

l=0
r=N-1
watched=[0]*N
while(True):
    p=(r+l)//2
    if watched[p]>0:
        if p<N-1 and watched[p+1]==0:
            p+=1
        else:
            break
    res=move(s,td,p)
    if res<0:
        l=p
        watched[p]=1
    else:
        r=p
        if watched[p]==0: watched[p]=2
ans_l=N
for i in range(N):
    if watched[i]==2:
        ans_l=i
        break

l=0
r=N-1
watched2=[0]*N
while(True):
    p=(r+l)//2
    if watched2[p]>0:
        if p<N-1 and watched2[p+1]==0:
            p+=1
        else:
            break
    res=move(s,td,p)
    if res>=N:
        r=p
        watched2[p]=3
    else:
        l=p
        if watched2[p]==0: watched2[p]=2
ans_r=-1
for i in range(N-1,-1,-1):
    if watched2[i]==2:
        ans_r=i
        break
print(max(0,ans_r-ans_l+1))


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


 int main()
 {
 	int a,b;
 	scanf("%d%d", &a,&b);
 	if(a<b)
 	{
 		printf("a < b\n");
	 }
	else if(a>b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
 		return 0;
 }


Measured memory_bytes: 2680
s = list(input())
if s[0] != "A" or s.count("A") != 1 or s.count("C") != 1 or s[2:-1].count("C") != 1:
    print("WA")
    exit()
s.sort()
for i in range(2, len(s)):
    if s[i].isupper():
        print("WA")
        exit()
print("AC")



Measured memory_bytes: 2940
S = list(input())

is_done_2 = False
is_done_3 = False

for i in range(len(S)-1):
    if len(set(S[i:i+2])) < 2:
        is_done_2 = True
        break

if not is_done_2:
    for j in range(len(S)-2):
        if len(set(S[j:j+3])) < 3:
            is_done_3 = True
            break

if is_done_2:
    print(i+1, i+2)
elif is_done_3:
    print(j+1, j+3)
else:
    print(-1, -1)


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    string S;
    cin >> S;
    vector<bool> F(26, true);
    int n = int(S.length());
    if(n == 26) {
        
        for (int i = 25; i >= 1; i--) {
            F = vector<bool>(26, true);
            if(S[i]+1 == S[i-1]) continue;
            else {
                rep(j,i-1) F[int(S[j]-'a')] = false;
                rep(j,26) if(F[j] && int(S[i-1]-'a') < j){
                    cout << S.substr(0,i-1) << char('a'+j) << endl;
                    return 0;
                }
                
            }
        }
        
        cout << -1 << endl;
        return 0;
    }
    
    
    rep(i,n) F[int(S[i]-'a')] = false;
    //rep(i,26) cout << F[i] << " ";cout << endl;
    rep(i,26) if(F[i]){cout << S << char('a'+i) << endl;return 0;}

    
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

		// 入力値の取得
		int L = sc.nextInt();
		
		// 結果の出力
		System.out.println(Math.pow(L, 3) / 27);

		sc.close();
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b == c || b + c == a || c + a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s=list(input())
n=len(s)
ans=0
for i in range(2**(n-1)):
	ni=list(map(int,list(str(format(i,"b")))))
	while len(ni)<n-1:
		ni.insert(0,0)
	siki=s[0]
	for j in range(n-1):
		if ni[j]==1:
			siki+="+"
		siki+=s[j+1]
	ans+=eval(siki)
print(ans)

	

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();
const long double EPS =1e-9;



int main(){
    ll n,res=0; cin>>n;
    ll a[3][n];
    REP(i,3){
        REP(j,n)cin>>a[i][j];
        sort(a[i],a[i]+n);

    }

    for (int i = 0; i < n; i++) {

      ll left_j = lower_bound(a[0], a[0]+n, a[1][i])-a[0];
      ll right_j =a[2]+n-upper_bound(a[2], a[2]+n,a[1][i]);
       res += 1LL *(right_j*left_j);
    }
    cout<<res<<endl;

}

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

int f;

int main(void)
{
	int n, m;

	while (scanf("%d %d", &m, &n) * m){
		int player[1024] = {0};
		int i, t, p;

		p = m;
		for (t=i=1;i<=n;i++){
			char say[9];
			char cmp[9]="";

			scanf("%s",say);
			i%3||strcat(cmp,"Fizz");
			i%5||strcat(cmp,"Buzz");
			*cmp||sprintf(cmp,"%d",i);

			strcmp(say,cmp)&&p>1&&(player[t]=p--);
			for(;player[t=t%m+1];);
		}
		for (f=i=1;i<=m;i++){
			player[i]||(f=!printf(" %d"+f,i));
		}
		puts("");
	}
}

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

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()

typedef long long ll;

const int mod = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) cin >> arr[i];
	int sum[n];
	sum[n - 1] = arr[n - 1];
	for (int i = n - 2; i > -1; i--) {
		sum[i] = sum[i + 1];
		sum[i] = (1LL * sum[i] + 1LL * arr[i]) % mod;
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans = (1LL * ans + 1LL * arr[i] * sum[i + 1]) % mod;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 5212
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
a = []
b = []
c = []
answer = 0
for i in range(n):
    b = []
    if not s[i] in a:
        a.append(s[i])
        if i < n-2:
            for j in range(i+1,n):
                c = []
                if not s[j] in b:
                    b.append(s[j])
                    if j < n-1:
                        for k in range(j+1,n):
                            if not s[k] in c:
                                c.append(s[k])
                                answer += 1
                            if len(c) == 10:
                                break
                if len(b) == 10:
                        break
        if len(a) == 10:
            break
print(answer)

Measured memory_bytes: 41708
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (N, A, B, C) = Slice4<int>();
            len = new int[N];
            for (var i = 0; i < N; ++i)
                len[i] = (int)Sarray()[0];
            nums = new int[N];
            WriteLine(dfs(0));
        }
        static int N;
        static int[] nums;
        static int[] len;
        static long INF = 1L << 32;
        static int A, B, C;

        static long dfs(int n)
        {
            if (n == N)
            {
                var mp = 0L;
                var trgt = new int[] { A, B, C };
                var sums = new int[4];
                for (var i = 0; i < N; ++i)
                    sums[nums[i]] += len[i];
                for (var i = 0; i < 3; ++i)
                {
                    var c = nums.Count(ns => ns == i);
                    if (c == 0) return INF;
                    //合成+調整
                    mp += 10 * (c - 1) + Abs(trgt[i] - sums[i]);
                }
                return mp;
            }
            var cst = INF;
            for (var i = 0; i < 4; ++i)//0:A,1:B,2:C,3:Non
            {
                nums[n] = i;
                cst = Min(cst, dfs(n + 1));
            }
            return cst;
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 46772
#include <stdio.h>
int main(){
    int K;
    int X;
    int A;
    int B;
    int C;
    scanf("%d %d",&A,&B);
    if(1<=A && A<=100){
        K=A;
    }
    if(0<=B && B<=100){
        X=B;
    }
    for(C=0;C<=2*K-2;C++){
        printf("%d ",X-K+1+C);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
using namespace std;

int D,N;
int main (){
    cin >> D >> N;
    int ans = 1;
    for(int i=0; i<D; i++){
        ans *= 100;
    }
    if( N == 100 ) N++;
    cout << N * ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX = 1e5 + 50 ;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , q , ans; string s ;
int t[101000] , sum[101000];

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

    cin >> s ;
    n = (int)s.length();
    ans = 0 ;
    for(int i = 0 ; i < n ; ++i){
        int j = i ;
        while(j < n && (s[j] == 'A' || s[j] == 'G' || s[j] == 'C' || s[j] == 'T'))
            ++j;
    ans = max((int)ans , j - i);
    }

    cout << ans << '\n';

     return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

using namespace std;

int main()
{
  int w, h, x, y;
  cin >> w >> h >> x >> y;

  double area = ((double)w * h / 2.0);
  cout << area;
  if (w == (x * 2) && h == (y * 2))
      cout << " 1" << endl;
  else
      cout << " 0" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    vector<int> v = {A, B, A-1, B-1};
    sort(v.begin(), v.end());

    cout << v[3] + v[2] << endl;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    int score[H][W];
    queue< pair<int, int> > blackList;
    for(int i = 0; i < H; i++) {
        string a;
        cin >> a;
        for(int j = 0; j < W; j++) {
            if('#' == a[j]) {
                blackList.push(pair<int, int>({i, j}));
                score[i][j] = 0;
            } else {
                score[i][j] = -1;
            }
        }
    }

    int cnt = 0;
    while(blackList.size() > 0) {
        int h = blackList.front().first;
        int w = blackList.front().second;
        blackList.pop();
        int s = score[h][w];
        if(h > 0) {
            if(score[h - 1][w] < 0) {
                blackList.push(pair<int, int>{h - 1, w});
                score[h - 1][w] = s + 1;
                cnt = max(cnt, s + 1);
            }
        }
        if(h < H - 1) {
            if(score[h + 1][w] < 0) {
                blackList.push(pair<int, int>{h + 1, w});
                score[h + 1][w] = s + 1;
                cnt = max(cnt, s + 1);
            }
        }
        if(w > 0) {
            if(score[h][w - 1] < 0) {
                blackList.push(pair<int, int>{h, w - 1});
                score[h][w - 1] = s + 1;
                cnt = max(cnt, s + 1);
            }
        }
        if(w < W - 1) {
            if(score[h][w + 1] < 0) {
                blackList.push(pair<int, int>{h, w + 1});
                score[h][w + 1] = s + 1;
                cnt = max(cnt, s + 1);
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 12304
#include <bits/stdc++.h>
using namespace std;
int len;
string s,s1,s2;
int main() {
	cin>>s;len=s.length();
	for(int i=len-1;i>=0;i--)s1=s1+s[i];
	for(int i=0;i<len;i++){
		if(s1[i]=='b')s2=s2+'d';
		if(s1[i]=='d')s2=s2+'b';
		if(s1[i]=='p')s2=s2+'q';
		if(s1[i]=='q')s2=s2+'p';
	}
	if(s==s2)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1004
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
#define endl "\n"
using namespace std;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x % y); }
void Run() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // freopen("mex.in", "r", stdin);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin); freopen("outt.txt", "w", stdout);
#endif
}
const int N = 1e5 + 10;
int f[N];
int e[N];
int main()
{
    Run();
    int n, m, a, b, cnt = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> f[i];
    while (m--)
    {
        cin >> a >> b;
        e[a] = max(e[a], f[b]);
        e[b] = max(e[b], f[a]);
    }
    for (int i = 1; i <= n; i++) {
        
        if (f[i] > e[i])
            cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 4404
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

/*
void visit(const Graph &g, vector< vector<int> > &adj, int s, vector<int> &path) {
  FOR(e, g[s]) if (adj[e->src][e->dst]) {
	--adj[e->src][e->dst];
	--adj[e->dst][e->src];
	visit(g, adj, e->dst, path);
  }
  path.push_back(s);
}
bool eulerPath(const Graph &g, int s, vector<int> &path) {
  int n = g.size();
  int odd = 0, m = 0;
  REP(i, n) {
	if (g[i].size() % 2 == 1) ++odd;
	m += g[i].size();
  }
  m /= 2;
  if (odd == 0 || (odd == 2 && g[s].size() % 2 == 0)) {
	vector< vector<int> > adj(n, vector<int>(n));
	REP(u, n) FOR(e, g[u]) ++adj[e->src][e->dst];
	path.clear();
	visit(g, adj, s, path);
	reverse(ALL(path));
	return path.size() == m + 1;
  }
  return false;
}
*/
typedef int Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

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

void visit(const Graph &g, vector< vector<int> > &adj, int s, vector<int> &path) {
	FOR(e, g[s]) if (adj[e->src][e->dst]) {
		--adj[e->src][e->dst];
		--adj[e->dst][e->src];
		visit(g, adj, e->dst, path);
	}
	path.push_back(s);
}
bool eulerPath(const Graph &g, int s, vector<int> &path) {
	int n = g.size();
	int odd = 0, m = 0;
	REP(i, n) {
		if (g[i].size() % 2 == 1) ++odd;
		m += g[i].size();
	}
	m /= 2;
	if (odd == 0 || (odd == 2 && g[s].size() % 2 == 0)) {
		vector< vector<int> > adj(n, vector<int>(n));
		REP(u, n) FOR(e, g[u]) ++adj[e->src][e->dst];
		path.clear();
		visit(g, adj, s, path);
		reverse(ALL(path));
		return path.size() == m + 1;
	}
	return false;
}

int main()
{
	int N = 4;
	Graph g(N);
	rep(i, 3) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		;
		g[a].emplace_back(a, b, 1);
		g[b].emplace_back(b, a, 1);
	}
	bool ans = false;
	rep(i, 4) {
		vector<int> path;
		if (eulerPath(g, i, path)) {
			ans = true;
			break;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


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

int main(void)
{
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    list<tuple<int, double>> degree;
    for(size_t i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        degree.push_back(make_tuple(i+1,abs((t-h*0.006)-a)));
    }
    degree.sort([](tuple<int, double> l, tuple<int, double> r) {
        return get<1>(l) < get<1>(r);
    });
    cout << get<0>(degree.front()) << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val inputs = LongArray(n) { readLine()!!.toLong()}

    // 数列の最小公倍数を求める問題 N <= 100
    // 最大公約数を求める方法から計算できるか？？

    // 15 と 21 -> 最大公約数 3  x 15/3 x 21/3 = 105 が最小公倍数
    // 次は 105 と次の数の最大公約数 -> 最小公倍数 ・・・　と求めていけばすべて求まるか？？

    if (n == 1) {
        print(inputs[0])
        return
    }

    var ans = getLeastCommonMultiple(inputs[0], inputs[1])

    for (i in 2 until n) {
        ans = getLeastCommonMultiple(ans, inputs[i])
    }

    print(ans)
}

fun getGreatestCommonDivisor(a: Long, b: Long): Long {
    if (a % b == 0L) {
        return b
    }
    return getGreatestCommonDivisor(b,a%b)
}

fun getLeastCommonMultiple(a:Long, b:Long): Long {
    val c = getGreatestCommonDivisor(a, b)
    // 下の計算を括弧を付けずに行うと，オーバーフローを起こすので注意
    return c * (a/c) * (b/c)
}

Measured memory_bytes: 31992
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll h, w; cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    vector<vector<ll>> cnt(h, vector<ll>(w, -1));
    ll white = 0;
    rep(y, h){
        rep(x, w){
            cin >> field[y][x];
            if(field[y][x] == '.') white++;
        }
    }

    queue<pair<ll, ll>> que;
    que.push(make_pair(h-1, w-1));
    cnt[h-1][w-1] = 0;
    ll dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; // U L D R
    while(!que.empty()){
        ll tx = que.front().second, ty = que.front().first;
        que.pop();
        rep(i, 4){
            ll nx = tx + dx[i], ny = ty + dy[i];
            if(nx < 0 || nx >= w) continue;
            if(ny < 0 || ny >= h) continue;
            if(field[ny][nx] == '#') continue;
            if(cnt[ny][nx] != -1) continue;
            que.push(make_pair(ny, nx));
            cnt[ny][nx] = cnt[ty][tx] + 1;
        }
    }
    if(cnt[0][0] == -1) cout << -1 << endl;
    else {
        ll ans = (white - 2) - (cnt[0][0] - 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

vector <int> adj[5];

int main() {
  for (int i = 0; i < 3; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector <int> vec;
  for (int i = 1; i <= 4; i++) {
    vec.push_back(adj[i].size());
  }
  sort(vec.begin(), vec.end());
  if (vec[0] == vec[1] && vec[0] == 1 && vec[2] == vec[3] && vec[2] == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    int a,b;

    cin >> a >> b;

    if(b <= (a+1)/2){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

    return 0;
}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	vector<int> b(n-1);

	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
	}

	int ans = b[0] + b[n - 2];

	for (int i = 1; i < n-1; i++) {
		ans += min(b[i - 1], b[i]);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] dp = new int[30];
		dp[0] = 1;
		dp[1] = 2;
		dp[2] = 4;
		for (int i = 3; i < 30; i++) {
			dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
		}
		
		while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			int d = dp[n - 1] / 10 + Math.min(1, dp[n - 1] % 10);
			int y = d / 365 + Math.min(1, d % 365);
			System.out.println(y);
		}
		
		sc.close();
	}
}

Measured memory_bytes: 26344