akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
///for ordered set///
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
///for ordered set///
 
using namespace std;
 
///for ordered set///
//using namespace __gnu_pbds;
//typedef tree< long long int , null_type, less_equal<long long int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
///for ordered set///
 
///Compiler Optimizer///
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
///Compiler Optimizer///
 
typedef long long           ll;
typedef unsigned long long  ull;
 
#define sf                  scanf
#define pf                  printf
#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define PF                  first
#define PS                  second
#define si(n)               scanf("%d",&n)
#define sii(x,y)            scanf("%d %d",&x,&y)
#define siii(x,y,z)         scanf("%d %d %d",&x,&y,&z)
#define sl(n)               scanf("%lld",&n)
#define sll(x,y)            scanf("%lld %lld",&x,&y)
#define slll(x,y,z)         scanf("%lld %lld %lld",&x,&y,&z)
#define FOR(i,x,y)          for(int i=x;i<y;i++)
#define RFOR(i,x,y)         for(int i=x;i>=y;i--)
#define CLR(arr,val)        memset(arr,val,sizeof arr);
#define vout(v)             for(int ind=0;ind<v.size();ind++){ cout<<v[ind]; if(ind<v.size()-1) cout<<' '; else cout<<endl;}
#define TCL(test,t)         for(test=1;test<=t;test++)
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define fastIO()            {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define MAXN                1000006
#define MAXP                1000006
#define MOD                 1000000007
#define PI                  acos(-1)

double arr[1000006];

int main(){
    #ifdef ELDUIVEL
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long int n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k)<<endl;
    #ifdef ELDUIVEL
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;

int k, q;
vector<int> d;

int solve (int n, int x, int m) {
    vector<int> dm;
    dm.reserve(k);

    for (auto v : d) {
        dm.eb(v % m);
    }

    x %= m;

    ll zs = 0;
    ll sum = x;
    for (int i=0; i<min(SZ(dm), n-1); i++) {
        int cnt = (n - i - 2) / k + 1;
        sum += 1LL * cnt * dm[i];
        debug(cnt, dm[i]);
        zs += (dm[i] == 0) * cnt;
    }
    debug(sum);

    return n - sum/m - zs - 1;
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> k >> q;

    d.resize(k);
    REP (i, k) {
        cin >> d[i];
    }

    while (q--) {
        int n, x, m;
        cin >> n >> x >> m;
        cout << solve(n,x,m) << endl;
    }
}


Measured memory_bytes: 384
package main

import (
  "fmt"
)

func main() {
  var n, m int
  fmt.Scanf("%d %d\n", &n, &m)
  
  r := 0
  if 2 <= n {
    r += n * (n -1) / 2
  }
  if 2 <= m {
    r += m * (m -1) / 2
  }

  fmt.Println(r)
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){
   
   double a,b,x;
   cin>>a>>b>>x;

    if(x <= a*a*b/2){
       double c = (x * 2)/(a*b);
       cout<<std::setprecision(10)<<90 - asin(c/sqrt(b*b + c*c))/(2*M_PI)*360.0<<endl;
    }else{
        double c = 2*x/(a*a) -b;
        cout<<std::setprecision(10)<<asin((b-c)/sqrt(a*a+(b-c)*(b-c)))/(2*M_PI)*360.0<<endl;
    }




    return 0;
}

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

using namespace std;

#define M_DEBUG if (0)

typedef unsigned long long int ullint;

/******************************************************************************
	Main
******************************************************************************/
int main()
{
	int h = -1, w = -1;
	cin >> h >> w;
	assert(h > 0 && h <= pow(10, 9));
	assert(w > 0 && w <= pow(10, 9));
	if (h == 1 || w == 1) {
		cout << 1 << endl;
		return 0;
	}


	 // 縦1, 3, 5, ... × 横 1, 3, 5, ... 奇数マスの個数
	ullint odd_h= (h % 2 == 0)? h / 2 : (h + 1) / 2;
	ullint odd_w = ((w % 2 == 0)? w / 2 : (w + 1) / 2);
	ullint odd_count =  odd_h * odd_w;

	 // 縦2, 4, 6, ... × 横 2. 4. 6, ... 偶数マスの個数
	ullint even_h= (h % 2 == 0)? h / 2 : (h - 1) / 2;
	ullint even_w = ((w % 2 == 0)? w / 2 : (w - 1) / 2);
	ullint even_count =  even_h * even_w;

	cout << odd_count + even_count << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
//#define int long long

const int MOD = 1e9 + 239;

ll n, m, a[500000];
ll c[500000];

signed main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    F(i, n) cin >> a[i];
    long long k = 2;
    F(i, n)
    {
        int x = a[i];
        while (x % 2 == 0)
        {
            x /= 2;
            c[i]++;
        }
        if (i > 0 && c[i] != c[i - 1])
        {
            cout << 0;
            return 0;
        }
    }
    F(i, n)
    {
        long long g = std::__gcd(k, a[i]);
        k = a[i] * k / g;
        if (k > 1000000000000LL)
        {
            cout << 0;
            return 0;
        }
    }
    if (k / 2 > m)
        cout << 0;
    else
        cout << max(0LL, (m - k / 2) / k + 1);
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  int a, b;
  cin >> a >> b;
  if((a * b) % 2){
    cout << "Odd" << endl;
  } else {
    cout << "Even" << endl;
  }


}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 200000;
long long x,n,D=0;
pair<long long, long long> itv[max_n];
long long a[max_n],b[max_n];
void solve(){
    long long count = 0;
    for(int i=0 ; i<n ; i++){
        long long wa = a[i+1] + a[i];
        if(wa > x){
            a[i+1] -= wa - x;
            count += wa -x;
            if(a[i+1]<0){
                a[i+1] = 0;
                a[i] += -a[i+1];
            }
        }
    }
    cout << count << endl;
}
int main(){
    cin >> n >> x;
    for(int i=0 ; i<n ; i++){
        cin >> a[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,cc; 
int main()
{
	cin>>a>>b>>c;
	cc=c-a-b;
	if(cc<=0)
	{
		cout<<"No"<<endl;
	}
	else if(cc*cc>4*a*b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
using namespace std;
vector<pll>vec[100005];
ll dist[100005];
void dfs(ll node,ll parent,ll value)
{
    dist[node]=value;
    for(auto i:vec[node]){
        if(i.ff==parent)continue;
        dfs(i.ff,node,value+i.ss);
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,b,c,q,k;
    cin>>n;
    for(int i=1;i<=n-1;i++){
        cin>>a>>b>>c;
        vec[a].pb({b,c});
        vec[b].pb({a,c});
    }
    cin>>q>>k;
    dfs(k,-1,0);
    while(q--){
        cin>>a>>b;
        cout<<dist[a]+dist[b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 16040
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<string>
#define ll long long
#define INF 0x3f3f3f3f
#define N 100005
using namespace std;
int main()
{
	char s[100],s1[100];
	scanf("%s%s",s,s1);
	if(s[0]==s1[2]&&s[1]==s1[1]&&s[2]==s1[0])
	printf("YES\n");
	else
	printf("NO\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)
#define P pair<int, int>

int main(){
    int n;
    cin >> n;
    P p[n];
    rep(i, n) {
        p[i].second = i + 1;
        cin >> p[i].first;
    }
    sort(p, p + n);
    rep(i, n)cout << p[i].second << " ";
    cout << endl;
    
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed<<setprecision(pp)
#define FOR(I,N) for(I=0;I<N;++I)
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod	%1000000007
#define pi 3.141592653
#define MX 1000000007

int main()
{
	ll n,i,ans=0,pr,tmp,x;
	cin>>n;
	cin>>pr;
	FOR(i,n-1)
	{
		cin>>x;
		tmp=(max((ll)0,pr-x));
		pr = tmp + x;
		ans += tmp;
	}
	cout<<ans;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t h, w, m;
    cin >> h >> w >> m;

    unordered_set<pair<int64_t, int64_t>, boost::hash<pair<int64_t, int64_t>>>
            targets;
    vector nh(h, 0L), nw(w, 0L);
    for (auto _ : irange(0L, m)) {
        int64_t y, x;
        cin >> y >> x;
        --y;
        --x;
        ++nh[y];
        ++nw[x];
        targets.emplace(y, x);
    }

    auto mxh = *max_element(nh.begin(), nh.end());
    auto mxw = *max_element(nw.begin(), nw.end());

    vector ih(0L, 0L), iw(0L, 0L);
    for (auto i : irange(0L, h)) {
        if (nh[i] == mxh) {
            ih.push_back(i);
        }
    }
    for (auto i : irange(0L, w)) {
        if (nw[i] == mxw) {
            iw.push_back(i);
        }
    }

    if (ih.size() * iw.size() > m) {
        cout << mxh + mxw << endl;
        return 0;
    }

    for (auto y : ih) {
        for (auto x : iw) {
            if (targets.count(make_pair(y, x)) == 0) {
                cout << mxh + mxw << endl;
                return 0;
            }
        }
    }

    cout << mxh + mxw - 1 << endl;
}

Measured memory_bytes: 34432
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        aa: [u64; 3*n],
    };
    let mut a = aa.clone();
    a.sort_by(|a, b| b.cmp(a));
    println!(
        "{}",
        a
        .iter()
        .take(2*n)
        .enumerate()
        .filter(|&(i, _)| i % 2 == 1)
        .map(|t| t.1)
        .sum::<u64>()
    );
}


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

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.nextLine());
			int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(r -> Integer.parseInt(r)).toArray();
			int[] B = Arrays.stream(sc.nextLine().split(" ")).mapToInt(r -> Integer.parseInt(r)).toArray();
			int[] C = Arrays.stream(sc.nextLine().split(" ")).mapToInt(r -> Integer.parseInt(r)).toArray();

			int sum = 0;
			for (int i = 0; i < N; i++) {
				sum += B[A[i] - 1];
				if (i > 0 && A[i - 1] + 1 == A[i]) {
					sum += C[A[i - 1] - 1];
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 27220
// https://atcoder.jp/contests/agc033/tasks/agc033_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

type V = usize;
type Graph = Vec<Vec<V>>;

fn diameter(g: Graph) -> usize {
    let (best_leaf, _) = dfs(&g, 0, g.len());
    let (_, diameter) = dfs(&g, best_leaf, g.len());
    diameter
}

fn dfs(g: &Graph, v: V, p: V) -> (V, usize) {
    let mut best_depth = 0;
    let mut best_leaf = v;
    for &t in &g[v] {
        if t == p {
            continue;
        }
        let (l, d) = dfs(g, t, v);
        if best_depth < d+1 {
            best_depth = d+1;
            best_leaf = l;
        }
    }
    (best_leaf, best_depth)
}

fn main() {
    input! {
        n: usize,
        edges: [(usize1, usize1); n-1]
    };

    let mut g = vec![vec![]; n];
    for e in edges {
        g[e.0].push(e.1);
        g[e.1].push(e.0);
    }

    let d = diameter(g);
    if (d+2) % 3 == 0 {
        println!("Second");
    } else {
        println!("First");
    }
}



Measured memory_bytes: 39412
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> as(n);
    REP(i, n) { cin >> as[i]; }
    sort(as.rbegin(), as.rend());
    int sum = 0;
    REP(i, n) { sum += as[i]; }
    if (as[m - 1] * 4 * m >= sum) {
        yes();
    } else {
        no();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,m;
  cin>>n>>m;
  map<int,int> v;
  vector<int> v1(n+1,0);
  ll a;
  string s;
  ll c=0,p=0;
  for(int i=0;i<m;i++)
  {
    cin>>a>>s;
    if(v[a]==0)
    {
        if(s=="AC")
        {
            c++;
            v[a]++;
            p+=v1[a];
        }
        else
        {
            v1[a]++;
        }
    }
    /*if(s=="AC")
    {
        if(!v[a])
        {
            c++;
            v[a]=true;
        }
    }
    else
    {
        if(!v[a])
        {
            p++;
        }
    }*/
  }
  cout<<c<<" "<<p<<endl;
  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	long long maxx = 0;
	if(a > maxx) maxx = a;
	if(b > maxx) maxx = b;
	if(c > maxx) maxx = c;
	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
		cout << 0;
	else if(a == maxx)
		cout << b * c;
	else if(b == maxx)
		cout << a * c;
	else if(c == maxx)
		cout << a * b;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

ll dp[51][51][2700];

int main() {

    
    ll n, kk;
    cin >> n >> kk;
    
    dp[0][0][0] = 1;
    
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            for (int k = 0; k <= kk; ++k)
            {
                if (j > 0)
                {
                    dp[i + 1][j - 1][k + 2 * (j - 1)] += j * j * dp[i][j][k];
                    dp[i + 1][j - 1][k + 2 * (j - 1)] %= mod;
                }
                dp[i + 1][j][k + 2 * j] += (2 * j + 1) * dp[i][j][k];
                dp[i + 1][j][k + 2 * j] %= mod;
                dp[i + 1][j + 1][k + 2 * (j + 1)] += dp[i][j][k];
                dp[i + 1][j + 1][k + 2 * (j + 1)] %= mod;
            }
        }
    }
    
    cout << dp[n][0][kk] << endl;
    
    return 0;
}

Measured memory_bytes: 54016
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ScopedTypeVariables #-}
-- {-# LANGUAGE FlexibleContexts #-}
-- {-# LANGUAGE ViewPatterns #-}
-- {-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
-- import qualified Data.Vector.Algorithms.Merge as VAM
-- import qualified Data.Heap as HP
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Debug.Trace

--------------------------------------------------------------------------
solve w h x y
    | (w == 2*x) && (h == 2*y) = (area,1)
    | otherwise = (area,0)
    where
        area = ((toDouble w) * (toDouble h)) / (toDouble 2)

main = do
    [w,h,x,y] <- singleLineToIntL
    let (area,vari) = solve w h x y
    putStrLn $ show area ++ " " ++ show vari
--------------------------------------------------------------------------

-- Input Util
int :: IO Int
int = readLn 

double :: IO Double
double = readLn 

str :: IO String
str = getLine

strBC :: IO BC.ByteString
strBC = BC.getLine

singleLineToIntL :: IO [Int]
singleLineToIntL = getLine >>= return . map read . words

singleLineToDoubleL :: IO [Double]
singleLineToDoubleL = getLine >>= return . map read . words

singleLineToIntV :: Int -> IO (VU.Vector Int)
singleLineToIntV n = BC.getLine >>= return . VU.unfoldrN n (BC.readInt . BC.dropWhile isSpace)

singleLineToDoubleV :: Int -> IO (VU.Vector Double)
singleLineToDoubleV n = BC.getLine >>= return . VU.fromList . map (read . BC.unpack) . BC.words

multipleLinesToIntL :: Int -> IO [Int]
multipleLinesToIntL n = replicateM n readLn

multipleLinesToDoubleL :: Int -> IO [Double]
multipleLinesToDoubleL n = replicateM n readLn

multipleLinesToIntV :: Int -> IO (VU.Vector Int)
multipleLinesToIntV n = VU.replicateM n readLn

multipleLinesToDoubleV :: Int -> IO (VU.Vector Double)
multipleLinesToDoubleV n = VU.replicateM n (BC.getLine >>= return . read . BC.unpack)

multipleLinesToTupleL :: Int -> IO [(Int, Int)]
multipleLinesToTupleL n = replicateM n (getLine >>= return . (\[a,b] -> (a,b)) . map read . words)

multipleLinesToTupleV :: Int -> IO (VU.Vector (Int, Int))
multipleLinesToTupleV n = VU.replicateM n $ do
    bs <- strBC
    let
        Just (a, bs') = BC.readInt $ BC.dropWhile isSpace bs
        Just (b, _) = BC.readInt $ BC.dropWhile isSpace bs'
    return (a,b)

-- others
strToChr :: String -> Char
strToChr [x] = x

chrToStr :: Char -> String
chrToStr x = [x]

m1 :: Int -> Int
m1 x = subtract 1 x

toDouble :: Int -> Double
toDouble x = fromIntegral x

toInt :: Double -> Int
toInt x = floor x

Measured memory_bytes: 508
#include "iostream"
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"OK"<<endl;
        exit(0);
    }
    int a,b;
    cin>>a>>b;

    
    
    for(int j=a;j<=b;j++)
    {
        if(j%n==0)
        {
            cout<<"OK"<<endl;
            exit(0);
        }
    }
    
    
    cout<<"NG"<<endl;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(){
	int a[4],b[4];
	int hit=0,blow=0,i,j,flag=0;

	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(a[i]==b[j] && i==j){
					hit++;
					break;
				}else if(a[i]==b[j]){
					flag=1;
				}
			}
			if(flag==1){
				blow++;
				flag=0;
			}
		}
		printf("%d %d\n",hit,blow);
		hit=0;
		blow=0;
		}
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

string s;
lint K;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> s >> K;
	lint N = SZ(s);
	REP(i, N) {
		if (s[i] == 'a') continue;
		int cost = 26 - (s[i] - 'a');
		if (K >= cost) {
			K -= cost;
			s[i] = 'a';
		}
	}
	K %= 26;
	s[N - 1] = s[N - 1] + K;
	cout << s << endl;
}


Measured memory_bytes: 592
N, M = map(int,input().split())
st = [[int(i) for i in input().split()] for j in range(N)]
cp = [[int(i) for i in input().split()] for j in range(M)]
for i in st:
    L = [abs(i[0] - j[0])+abs(i[1] - j[1]) for j in cp]
    m = min(L)
    print(L.index(m)+1)



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

int main() {
    int N;
    int d[110];
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> d[i];

    set<int> values;
    for (int i = 0; i < N; ++i) {
        values.insert(d[i]);
    }
    cout << values.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){

  unsigned long long n;
  unsigned long long *a, *seen;
  a = new unsigned long long[200001];
  unsigned long long k;
  seen = new unsigned long long[200001];
  // order = new unsigned long long[200001];
  vector<unsigned long long> order;

  cin >> n >> k;
  for(unsigned long long i = 0; i < n; i++) cin >> a[i];

  unsigned long long now = 0;
  unsigned long long counter = 1;
  bool flag = 0;
  unsigned long long ret = 0;
  seen[now] = 1;
  // order[0] = 0;
  order.push_back(0);
  while(!flag){
    now = a[now] - 1;
    if(seen[now] == 1) {
      flag = 1;
      ret = now;
      continue;
    }
    // order[counter] = now;
    order.push_back(now);
    seen[now] = 1;
    counter ++;
  }

  //order = {a,b,c,d,e}
  //ret = c
  unsigned long long size = order.size();
  unsigned long long roop = 0;
  for(unsigned long long i = 0; i < size; i++){
    // cout << order[i] << ',';
    if(order[i] == ret) roop = i;
  }
  // cout << endl;
  // printf("roop point = %d\r\n", roop);

  if(k <= roop){
    unsigned long long ans_pos = k % order.size();
    cout << order[ans_pos] + 1 << endl;

    delete[] a;
    delete[] seen;

    return 0;
  }

  k = k - roop;

  vector<unsigned long long> reorder;
  for(unsigned long long i = roop; i < size; i++){
    reorder.push_back(order[i]);
  }
  // for(int i = 0; i < reorder.size(); i++){
  //   cout << reorder[i] << ',';
  // }
  // cout << endl;

  
  // cout << size << endl;
  unsigned long long ans_pos = k % reorder.size();
  cout << reorder[ans_pos] + 1 << endl;

  delete[] a;
  delete[] seen;
  // delete[] order;


  return 0;
}

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

bool odd_dig(int i){
  int dig = 1;
  while (i / 10 > 0){
    dig++;
    i /= 10;
  }
  return ((dig % 2) ? true : false);
}
int main(){
  int n; cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++){
    if (odd_dig(i)) ans++;
  }
  cout << ans << endl;
}

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

public class Main {

	public static void main(String arg[]) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double[] p = new double[n + 1];

		for (int i = 1; i <= n; i++) {
			p[i] = scan.nextDouble();
		}

		double dp[][] = new double[n + 1][n + 1];
		
		
	    for(double[] arr : dp){
	        Arrays.fill(arr,-1);
	    }
		System.out.println(String.format("%.9f",probability(n, (n +1)/2, p, dp)));
	}

	public static double probability(int n, int x, double[] p, double[][] dp) {
		//System.out.println(n + "  " + x);
		if(x == 0)return 1;
		if (n == 0)
			return 0;
		
		if (dp[n][x] != -1) {
			return dp[n][x];
		}
		double withHead = p[n] * probability(n - 1, x - 1, p, dp);
		double withTail = (1 - p[n]) * probability(n - 1, x, p, dp);

		dp[n][x] = withHead + withTail;
		return dp[n][x];

	}
}


Measured memory_bytes: 118840
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define int long long
#define M 1000000007
#define pb push_back

using namespace std;



int32_t main(){
  boost;
  int t = 1; //cin>>t;
  while(t--)
  {
    int n, a , b;
    cin >> n >> a >> b;
    int ans = 0;
    if((b-a) % 2 == 0)
      ans = (b-a)/2;
    else
    {
      if(a-1 < n-b)
      {
        b = b - a;
        ans += a;
        a = 1;
        ans += (b-a)/2;
      }
      else
      {
        a = a + (n - b) + 1;
        ans += n - b + 1;
        b = n;
        ans += (b-a)/2;
      }
    }
    cout<<ans<<endl;

  }
}



Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
A = list(map(int, input().split()))

cnt = 0
d = defaultdict(int)
for i, a in enu(A):
    l = (i+1) + a
    r = (i+1) - a
    cnt += d[r]
    d[l] += 1
print(cnt)

Measured memory_bytes: 142868
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-04 16:46:46
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans;
    if (n % k == 0) ans = 0;
    else ans = 1;

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


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

int main(){


string sx,tx;

cin >> sx >> tx;

int cnt=0;
for(int i=0; i<sx.length(); i++){
    if(sx[i]!=tx[i]){
        cout << "No" << endl; 
        return 0;
    }
}
cout << "Yes" << endl;
}

Measured memory_bytes: 3596
n = int(input())

xy = []
for index in range(n):
  x, y = map(int, input().split())
  xy.append([x, y])

pos_max = xy[0][0]+xy[0][1]
pos_min = xy[0][0]+xy[0][1]
neg_max = xy[0][0]-xy[0][1]
neg_min = xy[0][0]-xy[0][1]
for item in xy:
  pos_v = item[0] + item[1]
  neg_v = item[0] - item[1]
  pos_max = pos_v if pos_v > pos_max else pos_max
  pos_min = pos_v if pos_v < pos_min else pos_min
  neg_max = neg_v if neg_v > neg_max else neg_max
  neg_min = neg_v if neg_v < neg_min else neg_min

pos_result = pos_max - pos_min
neg_result = neg_max - neg_min
print(pos_result if pos_result >= neg_result else neg_result)

Measured memory_bytes: 39012
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0)return a;
    return mygcd(b,a%b);
}

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

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

    string s;
    cin >> s;

    vector<int> str(n);
    for(int i = 0; i < n; i++){
        str[i] = (s[i] - '0');
    }

    vector<int> pos(3,0);
    ll ans = 0;

    for(int i = 0; i < 1000; i++){
        int fpos = 0;
        while(fpos < n && str[fpos] != pos[0]){
            fpos++;
        }
        fpos++;
        while(fpos < n && str[fpos] != pos[1]){
            fpos++;
        }
        fpos++;
        while(fpos < n && str[fpos] != pos[2]){
            fpos++;
        }
        if(fpos < n){
            ans++;
        }
        pos[2]++;
        if(pos[2] > 9){
            pos[2] = 0;
            pos[1]++;
            if(pos[1] > 9){
                pos[0]++;
                pos[1] = 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
ll N, A[MAX_N], B[MAX_N], C[MAX_N];

void solve() {
    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    ll ans = 0;
    REP(i, N) {
        ll *up_b = upper_bound(A, A + N, B[i] - 1);
        ll *up_c = upper_bound(C, C + N, B[i]);
        ans += (up_b - A) * (C + N - up_c);
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    solve();
    return 0;
}

Measured memory_bytes: 2560
from collections import Counter


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1


def main():
    n, k, l = map(int, input().split())
    a = UnionFind(n)
    b = UnionFind(n)
    for _ in range(k):
        p, q = map(int, input().split())
        a.union(p-1, q-1)
    for _ in range(l):
        r, s = map(int, input().split())
        b.union(r-1, s-1)
    d = Counter((a._root(i), b._root(i)) for i in range(n))
    print(*(d[(a._root(i), b._root(i))] for i in range(n)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44084
def resolve():
    N, M = list(map(int, input().split()))
    costs = []
    openables = []
    for i in range(M):
        a, b = list(map(int, input().split()))
        costs.append(a)
        C = list(map(int, input().split()))
        state = 0
        for c in C:
            state += (1<<(c-1))
        openables.append(state)
    
    dp = [[float("inf") for _ in range(4100)] for __ in range(10**3+100)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            opened_boxes = openables[i]
            dp[i+1][j|opened_boxes] = min(dp[i+1][j|opened_boxes], dp[i][j]+costs[i])
    print(dp[M][(1<<N)-1] if dp[M][(1<<N)-1] < float("inf") else -1)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 142220
N = int(input())
H = list(map(int,input().split()))

for i in range(N-1,0,-1):
    if H[i-1] == H[i] + 1:
        H[i-1] -= 1
    elif H[i-1] <= H[i]:
        continue
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=2e5+5;
ll a[M];
bool vis[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	vector<int> v;
	int c=1;
	while(1)
	{
		v.pb(c);
		vis[c]=1;
		c = a[c];
		if(vis[c])
			break;
	}
	std::vector<int> pr,pr2;
	bool f=0;
	for(int i=0;i<sz(v);i++)
	{
		if(v[i]==c)
			f=1;
		if(f==0)
			pr.pb(v[i]);
		else
			pr2.pb(v[i]);
	}
	if(k<sz(pr))
	{
		cout<<pr[k]<<"\n";
		return 0;
	}
	else
	{
		if(sz(pr))
			k-=sz(pr)-1;
		if(sz(pr))
			k--;
		cout<<pr2[k%sz(pr2)]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 7240
object Main {
  def main(args: Array[String]): Unit = {
    var line = scala.io.StdIn.readLine().split(" ")
    while (line(1) != "?") {
      line(1) match {
        case "+" => println(line(0).toInt + line(2).toInt)
        case "-" => println(line(0).toInt - line(2).toInt)
        case "*" => println(line(0).toInt * line(2).toInt)
        case "/" => println(line(0).toInt / line(2).toInt)
      }
      line = scala.io.StdIn.readLine().split(" ")
    }
  }
}

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

int main(void){
    int N,T,cost=1000,cnt=0;
    cin>>N>>T;
    int c[N],t[N];
    for(int i=0;i<N;i++){
        cin>>c[i]>>t[i];
        if(c[i]<=cost&&t[i]<=T){
            cost=c[i];
            cnt++;
        }
    }
    if(cnt==0)
        cout<<"TLE"<<endl;
    else
        cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  string s; cin>>s;

  vector<vector<int>> a(10);
  rep(i, n) {
    a[s[i]-'0'].push_back(i);
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) rep(k, 10) {
    if (a[i].empty() || a[j].empty() || a[k].empty()) continue;
    int ii = a[i][0];
    auto jter = upper_bound(a[j].begin(), a[j].end(), ii);
    if (jter == a[j].end()) continue;
    int jj = *jter;
    if (a[k].back() <= jj) continue;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3824
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			int M = scan.nextInt();
			char[]n = new char[N];
			char[]m = new char[M-1];
			Arrays.fill(n, '0');
			Arrays.fill(m, '1');
			String s = new String(n);
			String k = new String(m);
			String x = s+k;
			
			int Q = scan.nextInt();
			int[]a = new int[Q];
			int[]b = new int[Q];
			int[]c = new int[Q];
			int[]d = new int[Q];
			for(int i = 0;i<Q;i++) {
				a[i] = scan.nextInt();
				b[i] = scan.nextInt();
				c[i] = scan.nextInt();
				d[i] = scan.nextInt();
			}
			
			long max = 0;
			
			
			 while (true) {
			  //System.out.println(x);
				 int[]A = new int[N]; 
			  int count = 1;
			  int l = 0;
			  for(int i = 0;i<N+M-1;i++) {
				  char g = x.charAt(i);
				  if(g=='0') {
					  A[l] = count;
					  l++;
				  }else{
					  count++;
				  }
			  }
			  
			  for(int i = 0;i<N;i++) {
				 // System.out.print(A[i]);
				  //System.out.print(" ");
			  }
			  //System.out.println();
			  
			  long souwa = 0;
			  for(int i = 0;i<Q;i++) {
				  int o = A[b[i]-1]-A[a[i]-1];
				  if(o==c[i])souwa+=d[i];
			  }
			  
			  if(max<souwa)max = souwa;
			  
	
			  x = nextPermutation(x);
			  if (x.equals("Final")) break;
			  }
			 
			 System.out.println(max);
			
			
			
			
			
			
			
			
			
		}
		
		
	}
	
	
	//与えられた文字の種類と文字数を元に、初めの文字から順番に文字列を出力するメソッド
	//区別されているものを、順番に並べる通りを全列挙、、、、順列を順番に列挙(N種類ならN個の文字列になる必要がある。)
	//区別されていないもを、順番に並べる通りを全列挙,,,,,,組み合わせを順番に列挙になる。nCkなら０ｎ個１k個という順番でスターと。
	
	
	private static String nextPermutation (String s) {
		/*入力した文字列(数列、英語小文字、英語大文字)の次の順番を返すメソッド
		 * String s = "ABC";
		 * while (true) {
		 * System.out.println(s);
		 * s = nextPermutation(s);
		 * if (s.equals("Final")) break;
		 * }
		 * とmainメソッド に書けばN文字の文字列をN!文小さい物から順に列挙することができる*/

		ArrayList<Character> list = new ArrayList<>();
		for (int i=0; i<s.length(); i++) list.add(s.charAt(i));

		int pivotPos = -1;
		char pivot = 0;
		for (int i=list.size()-2; i>=0; i--) {
			if (list.get(i) < list.get(i+1)) {
				pivotPos = i;
				pivot = list.get(i);
				break;
			}
		}

		if (pivotPos==-1 && pivot==0) return "Final";

		int L = pivotPos+1, R = list.size()-1;
		int minPos = -1;
		char min = Character.MAX_VALUE;
		for (int i=R; i>=L; i--) {
			if (pivot < list.get(i)) {
				if (list.get(i) < min) {
					min = list.get(i);
					minPos = i;
				}
			}
		}

		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));

		StringBuilder sb = new StringBuilder();
		for (int i=0; i<list.size(); i++) sb.append(list.get(i));

		return sb.toString();

	}
	
	
	
	
		
	}





	
		





Measured memory_bytes: 66568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] A = new int[N+1];
		int[] B = new int[N];

		for (int i=0; i<N+1; i++){
			A[i] = sc.nextInt();
		}
		for (int i=0; i<N; i++){
			B[i] = sc.nextInt();
		}
		long killTotal = 0;
		for (int i=0; i<N; i++){
			int killCnt;
			if (A[i] > B[i]){
				killCnt = B[i];
				A[i] = A[i] - killCnt;
				B[i] = 0;
			} else {
				killCnt = A[i];
				A[i] = 0;
				B[i] = B[i] -killCnt;
			}
			killTotal += killCnt;
			killCnt = 0;
			if (A[i+1] > B[i]){
				killCnt = B[i];
				A[i+1] = A[i+1] - killCnt;
				B[i] = 0;
			} else {
				killCnt = A[i+1];
				A[i+1] = 0;
				B[i] = B[i] -killCnt;
			}
			killTotal += killCnt;
		}
		System.out.println(killTotal);
	}
}

Measured memory_bytes: 65160
#include <iostream>
#include <string>


using namespace std;
int main() {
    string w,t;
    cin >> w;
    int a=0;
    while(1){
        cin >> t;
        if (t =="END_OF_TEXT") break;
        for(int i=0;i<t.size();i++){
           t[i]= tolower(t[i]);
        }
        if(t==w)a++;
        }
    cout << a <<endl;
    }
    


Measured memory_bytes: 3164
#if 0
????????£?????????????´??????????
?????°?????¨??????dfs??????????????????????°??????§?????????
#endif

#include <iostream>
#include <vector>
using namespace std;
vector<int> E[101];
bool visited[101];
int in[101];
int out[101];
int count=0;
int nv(int n)
{
    int i=1;
    for(i=1;i<=n;i++)
    {
        if ( visited[i]==false )
            return i;
    }
    if (i>n) return 0;
}

void dfs(int n)
{
    visited[n]=true;
    in[n]=++count;
    for(vector<int>::iterator it=E[n].begin();it!=E[n].end();++it)
    {
        int now=*it;
        if(visited[now]==false)
            dfs(now);
    }
    out[n]=++count;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int e,n0;
        cin>>e>>n0;
        for(int j=0;j<n0;j++)
        {
            int t;
            cin>>t;
            E[e].push_back(t);
        }
        visited[i]=false;
        in[i]=out[i]=0;
    }

    int now=nv(n);
    while(now!=0)
    {
        dfs(now);
        now=nv(n);
    }


/*  for(int i=1;i<=n;i++)
    {
        for(vector<int>::iterator it=E[i].begin();it!=E[i].end();++it)
            cout<<*it<<" ";
        cout<<endl;
    }
*/
    for(int i=1;i<=n;i++)
        cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
    return 0;



}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

vector<ll> pos;
vector<ll> neg;
ll n,k;

ll check(ll x) {
    ll ans = 0;

    //neg neg
    ll p = neg.size()-1;
    ll nn = neg.size()-1;
    ll pp = pos.size()-1;

    for(ll i = 0; i < neg.size(); i++) {
        while(p >= 0 and neg[i]*neg[p] <= x) p--;
        ans += min(nn-p, nn-i);
    }
    //cout << ans << " | ";

    //pos pos
    p = 0;
    for(ll i = pos.size()-1; i >= 0; i--) {
        while(p < pos.size() and pos[i]*pos[p] <= x) p++;
        ans += min(p,i);
    }
    //cout << ans << " | ";

    //neg pos
    p = pos.size()-1;
    for(int i = neg.size()-1; i >= 0; i--) {
        while(p >= 0 and neg[i]*pos[p] <= x) p--;
        ans += pp-p;
    }

    //cout << x << " " << ans << endl;
    return (ans >= k);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        ll x; cin >> x;
        if(x >= 0) pos.pb(x);
        else neg.pb(x);
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    ll l = -1e18-5;
    ll ans = 0;
    ll r = 1e18+5;

    while(l <= r) {
        ll mid = (l+r) >> 1;
        if(check(mid)) ans = mid, r = mid-1;
        else l = mid+1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 2548
n = int(input())
*v, = map(int, input().split())
c = 0
for i in range(n):
    mi = i
    for j in range(i, n):
        if v[j] < v[mi]:
            mi = j
    if mi != i:
        c += 1
    v[i], v[mi] = v[mi], v[i]


print(" ".join([str(_v) for _v in v]))
print(c)


Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 1;;i++) {
			int num = sc.nextInt();
			if (num == 0) break;
			else System.out.print("Case " + i + ": " + num + "\n");
		}
	}
}


Measured memory_bytes: 41636