akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int[] x = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = s.nextInt();
    }
    int limit = s.nextInt();

    int[][] dptable = new int[18][n];

    int begin = 0;
    int end = 0;
    long sum = x[0];
    while (begin < n) {
      while (true) {
        if (end+1 < n && x[end+1] - x[begin] <= limit) {
          end++;
        } else {
          break;
        }
      }
      dptable[0][begin] = end;
      begin++;
    }
    for (int i = 1; i < 18; i++) {
      for (int j = 0; j < n; j++) {
        dptable[i][j] = dptable[i-1][dptable[i-1][j]];
      }
    }
/*
      System.out.println();
    for (int i = 0; i < 18; i++) {
      for (int j = 0; j < n; j++) {
        System.out.print(dptable[i][j]);
      }
      System.out.println();
    }
      System.out.println();
*/
    int q = s.nextInt();
    for (int i = 0; i < q; i++) {
      int ta = s.nextInt() - 1;
      int tb = s.nextInt() - 1;
      int a = Math.min(ta, tb);
      int b = Math.max(ta, tb);
/*
      if (dptable[0][a] >= b) {
        System.out.println(1);
        continue;
      }
*/
      int current = a;
      int days = 0;
      int depth = 0;
      for (depth = 0; depth < 17; depth++) {
        if (dptable[depth+1][current] >= b) {
          current = dptable[depth][current];
          days = 1 << depth;
          break;
        }
      }
      while (depth >= 0) {
//        System.out.printf("%d %d\n", depth, current);
        if (dptable[depth][current] < b) {
          current = dptable[depth][current];
          days += (1 << depth);
        }
        depth--;
      }
//        System.out.printf("%d %d\n", depth, current);
      System.out.println(days + (current < b ? 1 : 0));
    }
  }
}


Measured memory_bytes: 95184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	string S,T; cin >> S >> T;
	int ans = 0;
	rep(i,3){
		if(S[i] == T[i]) ans++;
	}
	cout << ans << endl;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
ll K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S>>K;
	FOR(i,K) {
		if(S[i]!='1') return _P("%c\n",S[i]);
	}
	_P("%c\n",S[K-1]);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	b := NewBoard()

	s := bufio.NewScanner(os.Stdin)

	//いらないので一行消している
	s.Scan()

	for s.Scan() {
		text := s.Text()

		marks := strings.Split(text, "")
		b.AddLine(marks...)
	}

	count := 0
	for {
		if len(b.NextBlackSwitch) == 0 {
			break
		}

		b.Reverse()
		count++
	}

	fmt.Print(count - 1)
}

const (
	blackMark = "#"
	whiteMark = "."
)

type Board struct {
	Squares         [][]*Square
	NextBlackSwitch []*Square
}

func NewBoard() *Board {
	return &Board{}
}

func (b *Board) AddLine(marks ...string) {
	line := make([]*Square, len(marks))

	for i := range marks {
		s := NewSquare(len(b.Squares), i, marks[i])
		if s.IsBlack() {
			b.NextBlackSwitch = append(b.NextBlackSwitch, s)
		}

		line[i] = s
	}

	if len(b.Squares) > 0 {
		for i := range line {
			b.Squares[len(b.Squares)-1][i].down = line[i]
			line[i].up = b.Squares[len(b.Squares)-1][i]
		}
	}

	for i := range line {
		if i != 0 {
			line[i].left = line[i-1]
		}

		if i+1 != len(line) {
			line[i].right = line[i+1]
		}
	}

	b.Squares = append(b.Squares, line)
}

func (b *Board) Reverse() {
	next := make([]*Square, 0)
	for i := range b.NextBlackSwitch {
		if b.NextBlackSwitch[i].up != nil {
			if already := b.NextBlackSwitch[i].up.Reverse(); !already {
				next = append(next, b.NextBlackSwitch[i].up)
			}
		}

		if b.NextBlackSwitch[i].down != nil {
			if already := b.NextBlackSwitch[i].down.Reverse(); !already {
				next = append(next, b.NextBlackSwitch[i].down)
			}
		}

		if b.NextBlackSwitch[i].right != nil {
			if already := b.NextBlackSwitch[i].right.Reverse(); !already {
				next = append(next, b.NextBlackSwitch[i].right)
			}
		}

		if b.NextBlackSwitch[i].left != nil {
			if already := b.NextBlackSwitch[i].left.Reverse(); !already {
				next = append(next, b.NextBlackSwitch[i].left)
			}
		}
	}

	b.NextBlackSwitch = next
}

type Square struct {
	line  int
	row   int
	mark  string
	up    *Square
	down  *Square
	right *Square
	left  *Square
}

func NewSquare(row int, line int, mark string) *Square {
	return &Square{
		line: line,
		row:  row,
		mark: mark,
	}
}

func (s *Square) IsBlack() bool {
	return s.mark == blackMark
}

func (s *Square) Reverse() (already bool) {
	if s == nil {
		return true
	}

	if s.IsBlack() {
		return true
	}

	s.mark = blackMark
	return false
}


Measured memory_bytes: 110464
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> tall(n);
  for(int i=0 ;i<n;i++){
    cin >> tall.at(i);
  }
  
  int ans=0;
  for(int i=0 ; i<n ;i++){
    if(tall.at(i)>=k){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

mod = 10 ** 9 + 7
w = 0
for i in range(n-1):
    w += (x[i+1] - x[i]) * (i+1) * (n-i-1)
    w %= mod
h = 0
for j in range(m-1):
    h += (y[j+1] - y[j]) * (j+1) * (m-j-1)
    h %= mod
print(h * w % mod)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  ll a, b;
  scanf("%lld %lld", &a, &b);

  set<ll> s;
  s.insert(1);
  s.insert(2);
  s.insert(3);

  s.erase(a);
  s.erase(b);

  for (ll i = 1; i <= 3; i++) {
    if (s.find(i) != s.end()) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
use std::io::Read;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: u32 = read();
    let q: usize = read();
    let mut a = vec![n; q];
    for i in 0..q {
        let a_: usize = read();
        a[i] = a_ - 1;
    }

    let mut count: Vec<i32> = vec![0; n];
    for &v in a.iter() {
        count[v] += 1;
    }

    for i in 0..n {
        count[i] = k as i32 + (count[i] as i32 - q as i32);
    }

    for &v in count.iter() {
        if v >= 1 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

ll dp[105][105][305];

int main(){
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n);
    vector<ll> v(n);
    rep(i, n) cin >> w[i] >> v[i];
    dp[0][0][0] = 0;
    for (ll i=1; i<=n; i++) {
        for (ll j=0; j<=i; j++) {
            for (ll k=0; k<=3*j; k++) {
                ll total = w[0]*j + k;
                if (total>W) continue;
                dp[i][j][k] = dp[i-1][j][k];
                ll iw = w[i-1] - w[0];
                ll iv = v[i-1];
                if (j>0 && k-iw>=0) {
                    chmax(dp[i][j][k], dp[i-1][j-1][k-iw]+iv);
                }
            }
        }
    }
    ll ans = 0;
    rep(j, 105) rep(k, 305) {
        chmax(ans, dp[n][j][k]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16160
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>

using namespace std;


int main()
{
  int n, tp = 0, hp = 0;
  string t, h;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> t >> h;
    if(t == h)
    {
      tp++;
      hp++;
      continue;
    }
    if(t < h)
    {
      hp += 3;
      continue;
    }
    if(t > h)
    {
      tp += 3;
      continue;
    }
  }
  cout << tp << " " << hp << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005,Mod=1e9+7;
int a[N];
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&a[i]);
	sort(a+1,a+n+1);int ans=0,all=1ll*qpow(2,n)*qpow(2,n)%Mod;
	int inv2=qpow(2,Mod-2);all=1ll*all*inv2%Mod;
	for (int i=1;i<=n;i++)
		ans=(ans+1ll*all*(n-i+2)%Mod*inv2%Mod*a[i])%Mod;
	printf ("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    string Sc;
    cin>>Sc;
    int ans=INF;
  	string S;
    for(int i=0;i<26;i++){
        S=Sc;
      	int count=0;
        char d='a'+i;
        bool ok=true;
        REP(i,S.size()-1){
            if(S[i]!=S[i+1])ok=false;
        }
      	if(ok)ans=0;
        while(!ok){
            bool che=false;
            REP(i,S.size()-1){
                if(S[i]==d||S[i+1]==d){
                    S[i]=d;
                    che=true;
                }
            }
            if(!che){
                break;
            }
            count++;
            S=S.substr(0,S.size()-1);
            ok=true;
            REP(i,S.size()-1){
            if(S[i]!=S[i+1])ok=false;
            }
        }
        if(count!=0)ans=min(count,ans);    
    }
  	cout<<ans<<endl;
}

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

int main() {
	int x,y;
	cin>>x>>y;
	if(abs(x-y)>=2){
		cout<<max(x,y)*2-1<<endl;
	}else{
		cout<<x+y<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    rep(i, s.size()) {
        if (s[i] != t[i])
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3920
#include <stdio.h>

int main(){
  int S;
  int i;

  scanf("%d",&S);

  int flag=0;
  if(S/100>0&&S/100<=12)flag++;
  if(S%100>0&&S%100<=12)flag+=2;
  
  if(flag==1)printf("MMYY\n");
  else if(flag==2)printf("YYMM\n");
  else if(flag==3)printf("AMBIGUOUS\n");
  else printf("NA");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int N,te,ans,cur,be,af;
int main(){
    cin >> N;
    vector<int> vec;
    int ans=100;
    for(int i=0;i<N;i++){
        cin >> te;
        vec.push_back(te);
    }
    for(int i=1;i<N;i++){
        be = std::accumulate(vec.begin(), vec.end()-(N-i), 0);
        af = std::accumulate(vec.begin()+i, vec.end(), 0);
        cur = abs(be-af);
        if(cur<ans) ans = cur;
    }
    cout << ans;
}


Measured memory_bytes: 256
/*input
10
5 9 5 9 8 9 3 5 4 3

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

int n;
vector<int> a, ta;
vector<pair<int, int> > b;

int tree[200010];

int get(int i) {
	int ret = 0;
	i += 100005;
	for (; i < 200010; i += i & -i) {
		ret += tree[i];
	}
	return ret;
}

void update(int i, int val) {
	i += 100005;
	for (; i; i -= i & -i) {
		tree[i] += val;
	}
}

int countArr(int mid) {
	ta.clear(); memset(tree, 0, sizeof(tree));
	for (auto it : a) {
		if (it > mid) ta.push_back(1);
		else ta.push_back(-1);
	}
	// tong duong
	int sum = 0; int ret = 0;
	update(0, 1);
	for (int i = 0; i < n; i++) {
		sum += ta[i];
		ret += get(sum + 1);
		update(sum, 1);
	}
	return ret;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int t; cin >> t;
		a.push_back(t);
		b.push_back(mp(t, i - 1));
	}
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		a[b[i].se] = i;
	}
	int l = 0, r = n - 1;
	int all = n * (n + 1) / 2;
	all = all / 2 + 1;
	while (l != r) {
		int mid = (l + r) / 2;
		int rec = countArr(mid);
		// cout << mid << sp << rec << sp << all << endl;
		if (rec >= all) r = mid;
		else l = mid + 1;
	}
	// cout << b << endl;
	cout << b[l].fi << endl;
}

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

class Dice {
  int U, D, N, E, S, W;

  void goN() {
    int tmp = U;
    U = S;
    S = D;
    D = N;
    N = tmp;
  }

  void goE() {
    int tmp = U;
    U = W;
    W = D;
    D = E;
    E = tmp;
  }

  void goS() {
    int tmp = U;
    U = N;
    N = D;
    D = S;
    S = tmp;
  }

  void goW() {
    int tmp = U;
    U = E;
    E = D;
    D = W;
    W = tmp;
  }

  public:
  Dice(vector<int> label) {
    U = label.at(0);
    S = label.at(1);
    E = label.at(2);
    W = label.at(3);
    N = label.at(4);
    D = label.at(5);
  }

  void go(char way) {
    switch(way) {
      case 'N':
        goN();
        break;
      case 'E':
        goE();
        break;
      case 'S':
        goS();
        break;
      case 'W':
        goW();
        break;
    }
  }

  char getPos(int label) {
    if (U == label) return 'U';
    else if (D == label) return 'D';
    else if (N == label) return 'N';
    else if (E == label) return 'E';
    else if (S == label) return 'S';
    else if (W == label) return 'W';
    return 'Z';
  }

  int getLabel(char pos) {
    if (pos == 'U') return U;
    else if (pos == 'D') return D;
    else if (pos == 'N') return N;
    else if (pos == 'E') return E;
    else if (pos == 'S') return S;
    else if (pos == 'W') return W;
    return -1;
  }
};

int main() {
  vector<int> label(6);
  for (int i = 0; i < 6; ++i) cin >> label.at(i);
  Dice d1(label);
  string command;
  cin >> command;
  for (int i = 0; i < command.size(); ++i) {
    d1.go(command.at(i));
  }
  cout << d1.getLabel('U') << endl;

  return 0;
}


Measured memory_bytes: 3204
#1行目が文字列の場合
#数値が与えられるが各桁毎の処理が必要な場合には文字列として読み込んだ方が処理しやすい
s = str(input())

#連続する文字列が同じかを確認する
#とある i に対してその 1つ前の文字が同じならば同じ文字列が連続している
#この場合にfor文は1から処理する
#for i in range(start, end, step)
#start = 開始値（以上。1の場合1から開始）
#end = 終了値（未満。5の場合4で終了）
#step = 間隔？（2の場合は2増加する）
#for i in range(1, 10, 2):ならiの値は「1, 3, 5, 7, 9」となる
for i in range(1, len(s)):
    #i番目の文字がi-1(ひとつ前の文字)と一致する場合
    if s[i] == s[i-1]:
        print("Bad")
        #プログラムを終了
        exit()
#連続文字列がない場合
print("Good")


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

signed main(){
	int n,k,a[100010],imos[100010] = {};
	cin >> n >> k;
	Combination<modint<>> comb(100010);
	for(int i = 0;i < n;i++) cin >>	a[i];
	sort(a,a + n);
	if(k == 1){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 0;i < n;i++) imos[i + 1] = imos[i] + a[i];
	modint<> ans = 0;
	for(int i = k;i <= n;i++){
		modint<> tmp = imos[n] - imos[i - 1] - imos[n - i + 1];
		ans += tmp * comb.nCr(i - 2,k - 2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>	// 入出力
#include<stdio.h>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;

using ll = long long;


int A[200][2];

int N;


int main()
{
	
	cin >> N;

	int total = 0;

	for (int i = 0; i < N; ++i)
	{
		cin >> A[i][0];
		total += A[i][0];
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i][1];
	}

	total += A[N - 1][1];

	int ans = total;

	for (int i = 1; i < N; ++i)
	{
		total -= A[N - i][0];
		total += A[N-i-1][1];
		if (total > ans) { ans = total; }
	}

	cout << ans << endl;



	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = min(a,b) + min(c,d);
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 3520
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";
std::set<string> V;
ll K;

int main() {
	cin >> S;
	scanf("%lld", &K);
	int sz = S.size();
	for(int i = 1; i <= min(5, sz); i++) {
		for(int j = 0; j <= S.size() - i; j++) {
			V.insert(S.substr(j, i));
			// if(V.size() >= 5) {}
		}
	}
	// sort(V.begin(), V.end());
	set<string> :: iterator itr;
	ll cnt = 0;
	for(itr = V.begin(); itr != V.end(); itr++) {
		cnt++;
		if(cnt == K) {
			cout << *itr << " ";
			break;
		}
	}
	// auto itr = V.begin() + K;
	// advance(itr, K - 1);
	// cout << *itr << " ";

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] c = new int[10][10];
        for (int i = 0 ; i < 10 ; i++) {
            for (int j = 0 ; j < 10 ; j++) {
                c[i][j] = sc.nextInt();
            }
        }
        int[][] a = new int[h][w];
        for (int i = 0 ; i < h ; i++) {
            for (int j = 0 ; j < w ; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        int inf = 100000;
        for (int k = 0 ; k < 10 ; k++) {
            for (int j = 0 ; j < 10 ; j++) {
                for (int i = 0 ; i < 10 ; i++) {
                    c[i][j] = Math.min(c[i][j], c[i][k]+ c[k][j]);
                }
            }
        }
        int ans = 0;
        for (int i = 0 ; i < h ; i++) {
            for (int j = 0 ; j < w ; j++) {
                if (a[i][j] != -1) {
                    ans += c[a[i][j]][1];
                }
            }
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 47564
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n, a[100], res = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a, a + n, greater<int>());
    for (int i = 0; i < n; i++)
        res += a[i] * (i % 2 == 0 ? 1 : -1);
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int n;
    cin >> n;

    vector<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    vector<ll> v2(n);
    for(ll i = 0; i < n; i++) v2[i] =  v[i] - i;
    
    ll ans = 0;
    map<ll, ll> m;
    for(int i = 0; i < n; i++){
        m[ v2[i] ] ++;
    }

    for(ll i = 0; i < n; i++){
        m[ v2[i] ] --;
        ans += m[ -( i + v[i]) ];
    }

    for(auto it = m.begin(); it != m.end(); it++ ){
      //  cout << it->first <<":" << it->second << endl;
    }
    cout << ans << endl;
    /*
    for(int diff = 1; diff < n; diff++){
        for(int i = 0; i + diff < n; i++){
            if( v[i] + v[i + diff] == diff ){
                ans ++;
            }
        }
    }
    */

    return 0;
}

Measured memory_bytes: 28972
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a+b == 15){
            System.out.println("+");
        }
        else if(a*b == 15){
            System.out.println("*");
        }else{
            System.out.println("x");
        }
    }
}

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


int main(){
    int n;
    int p[30]={};
    int ans = 0;
    cin >> n;
    for(int i = 1; i <=n; i++) cin >> p[i];

    for(int i = 1; i <=n-2; i++){
        if((p[i]<p[i+1]&&p[i+1]<=p[i+2])||(p[i+2]<p[i+1]&&p[i+1]<=p[i])){
            ans++;
        }
    }
  
    cout << ans<<"\n";
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


// 753
int dp[20][2][10], mp[10];
bool ok(int num){
  if(num == 0 or num == 7 or num == 5 or num == 3)return true;
  else return false;
}

signed main(){
  mp[0] = 0;mp[3] = 1;mp[5] = 1<<1, mp[7] = 1<<2;
  string str;
  cin >> str;
  int n = str.size();
  dp[0][0][0] = 1;
  rep(i,n){
    rep(j,10){
      int num = str[i]-'0';
      rep(k,1<<3)if(ok(j)){
        if(k > 0 and j == 0)continue;
        // dp[i+1][1] += dp[i][1];
        dp[i + 1][1][k | mp[j]] += dp[i][1][k];
        if(j < num){
          // dp[i+1][1] += dp[i][0];
          if (ok(j))dp[i + 1][1][k | mp[j]] += dp[i][0][k];
        }else if(j == num){
          // dp[i+1][0] += dp[i][0];
          if (ok(j))dp[i + 1][0][k | mp[j]] += dp[i][0][k];
        }
      }
    }
  }
  // rep(i,n+1)printf("%lld ", dp[i][1][(1<<3)-1]);printf("\n");
  // printf("%lld\n", dp[n][0][(1<<3)-1]);
  printf("%lld\n", dp[n][1][(1<<3)-1] + dp[n][0][(1<<3)-1]);
  return 0;
}

Measured memory_bytes: 256
def is_prime(x):
  if x < 2:
    return False
  if x == 2 or x == 3 or x == 5:
    return True
  if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
    return False
  prime = 7
  step = 4
  while prime <= pow(x, 1/2):
      if x % prime == 0:
        return False
      prime += step
      step = 6 - step
  return True


res = int(input())
p = res
flg = 0
while flg == 0:
  if is_prime(p) and p >= res:
    res = p
    flg = 1
  p += 1
print(res)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = 0;
    for (int i=1;i<=N;i++){
      String iStr = String.valueOf(i);
      String[] iSpl = iStr.split("");
      int[] iInt = new int[iSpl.length];
      int sum = 0;
      for (int j=0;j<iSpl.length;j++) {
        iInt[j] = Integer.parseInt(iSpl[j]);
        sum = sum + iInt[j];
      }
      if ((sum>=A)&&(sum<=B)) {
        ans = ans + i;
      }
    }
    System.out.println(ans);
  }
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define GOOGLE 0
#define MULTIPLE_TC 0

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  long long sum = 0;
  sum += 1 * min(a, k);
  k -= min(a, k);
  sum += 0 * min(b, k);
  k -= min(b, k);
  sum -= 1 * min(c, k);
  k -= min(c, k);
  cout << sum << '\n';
}

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

  pre();

  int t = 1, T;

  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}


Measured memory_bytes: 3792
import java.util.*;
 
public class Main {
  static int[] list;
    public static void main(String[] args) throws Exception{
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] s = new String[n];
      for (int i = 0; i<n;i++) {
        char[] chars = sc.next().toCharArray();
        Arrays.sort(chars);
        s[i] = String.valueOf(chars);
      }
      Arrays.sort(s);
      long cnt = 0;
      long cnt1 = 0;

      for(int i=0;i<n-1;i++) {
        if(s[i].equals(s[i+1])) {
          cnt1++;
          cnt+=cnt1;
        }else {
          cnt1=0;
        }
      }
      System.out.println(cnt);
    }
}


Measured memory_bytes: 52104
package main

import "fmt"

func main() {
    var a,b int

    fmt.Scan(&a, &b)
    ans := "No"

    for i := 0; i <= b; i++ {
        if(a%500 == i) {
            ans = "Yes"
            break
        }
    }

   fmt.Println(ans)
}

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

unsigned long long ans=0;
vector<int> a;
void rec(int sum, int odd, int even)
{
  if(odd+even==0){
    if(sum%10==0)ans++;
    return;
  }
  for(int i=0; i<a.size(); i++){
    if(odd)rec(sum+a[i], odd-1, even);
    else rec(sum+(2*a[i]/10)+((2*a[i])%10), odd, even-1);
  }
}

int main()
{
  int n,m;
  cin>>n;
  vector<char>ID(n);
  int sum=0;
  int odd=0,even=0;
  bool flagOdd=n&1;
  flagOdd^=1;
  for(int i=0; i<n; i++){
    cin>>ID[i];
    flagOdd^=1;
    if(ID[i]=='*'){
      if(flagOdd)odd++;
      else even++;
      continue;
    }
    ID[i]-='0';
    if(flagOdd)sum+=ID[i]%10;
    else sum+=(2*ID[i]/10)+((2*ID[i])%10);
  }
  cin>>m;
  a.resize(m);
  for(int i=0; i<m; i++){
    cin>>a[i];
  }
  rec(sum, odd, even);
  cout<<ans<<endl;
}

Measured memory_bytes: 1296
use std::io;


/// https://beta.atcoder.jp/contests/abc089/tasks/abc089_b
fn main() {
    let _n = read_one::<usize>();
    let mut sn = read::<String>();
    sn.sort();
    sn.dedup();
    if sn.len() == 3 { println!("Three"); }
    else { println!("Four"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
s = int(input())
a = [False for i in range(1000000)]
num = 0

while True:
    num += 1
    if a[s] == True:
        print(num)
        break
    
    a[s] = True
    s = s // 2 if s % 2 == 0 else s * 3 + 1    


Measured memory_bytes: 10952
def solve():
	from collections import deque
	n,*l=map(int,open(0).read().split())
	con=[[] for _ in range(n)]
	dist=[None]*n
	dist[0]=0
	for a,b,c in zip(*[iter(l)]*3):
		con[a-1].append((b-1,c%2))
		con[b-1].append((a-1,c%2))
 
	que=deque([0])
	while que:
		cur=que.popleft()
		for nxt,d in con[cur]:
			if dist[nxt]==None:
				que.append(nxt)
				dist[nxt]=(dist[cur]+d)%2

	print(*dist,sep="\n")

if __name__=="__main__":
	solve()

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 100000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int w,h;
    cin >> w >> h;
    if(w==0) return 0;
    vector<vector<int>> s(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++) cin >> s[i][j];
    }
    vector<int> c(4),vx={1,0,-1,0},vy={0,1,0,-1};
    cin >> c[0] >> c[1] >> c[2] >> c[3];
    vector<vector<vector<int>>> dist(h,vector<vector<int>>(w,vector<int>(4,INF)));
    priority_queue<pair<int,tuple<int,int,int>>> dijk;
    dijk.push({0,make_tuple(0,0,0)});
    pair<int,tuple<int,int,int>> now;
    int nx,ny,muki;
    while(!dijk.empty()){
      now=dijk.top();
      dijk.pop();
      if(dist[get<1>(now.second)][get<0>(now.second)][get<2>(now.second)]==INF){
        dist[get<1>(now.second)][get<0>(now.second)][get<2>(now.second)]=-now.first;
        if(get<1>(now.second)==h-1&&get<0>(now.second)==w-1){
          // for(int k=0;k<4;k++){
          //   for(int i=0;i<h;i++){
          //     for(int j=0;j<w;j++){
          //       cout << dist[i][j][k] << " ";
          //     }
          //     cout << endl;
          //   }
          //   cout << endl;
          // }
          cout << -now.first << endl;
          break;
        }
        for(int i=0;i<4;i++){
          muki=(get<2>(now.second)+i)%4;
          nx=get<0>(now.second)+vx[muki];
          ny=get<1>(now.second)+vy[muki];
          if(0<=nx&&nx<w&&0<=ny&&ny<h){
            if(dist[ny][nx][muki]==INF){
              if(s[get<1>(now.second)][get<0>(now.second)]==i){
                dijk.push({now.first,make_tuple(nx,ny,muki)});
              }else{
                dijk.push({now.first-c[i],make_tuple(nx,ny,muki)});
              }
            }
          }
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3288
#include<stdio.h>

int main(void){
	double a,b,c,d,e,f;
	double x,y;

	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
		x=(a*c*e-c*d*b-a*b*f+b*d*c)/(a*a*e-a*b*d);
		y=(a*f-d*c)/(a*e-d*b);
		printf("%.3lf %.3lf\n",x+0.0,y+0.0);
	}
	return 0;
}

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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

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

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

	map<string, ll> mp;
	rep ( i, n ) {
		string str;
		cin >> str;

		mp[str]++;
	}

	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, a;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            ans++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3636
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_tpl):
        self.faces = str_tpl

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return 'Yes'
        return 'No'


str_tpl1 = tuple(input().split())
dice1 = Dice(str_tpl1)

str_tpl2 = tuple(input().split())
dice2 = Dice(str_tpl2)

print(dice1.is_same(dice2))

Measured memory_bytes: 7620
# util functions
include Math

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

ss = inputs[0][0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p ss
end


sqrt_ss = sqrt(ss)
aa = sqrt_ss.ceil
dd = sqrt_ss.floor

if aa == dd
  puts "0 0 #{aa} 0 0 #{dd}"
  exit
end


if aa*dd - ss > 0
  bb = aa*dd - ss
  puts "0 0 #{aa} #{bb} 1 #{dd}"
else # aa*dd - ss < 0
  cc = ss - aa*dd
  puts "0 1 #{aa} 0 #{cc} #{dd + 1}"
end


Measured memory_bytes: 1788
# input
N = int(input())

# check
c = [list(range(1, 10))]
for i in range(9):
    tmp = []
    append = tmp.append
    for val in c[-1]:
        if val % 10 != 0:
            append(val * 10 + (val % 10 - 1))
        append(val * 10 + (val % 10))
        if val % 10 != 9:
            append(val * 10 + (val % 10 + 1))
    c.append(tmp)

ans = []
set = ans.append
for i in range(len(c)):
    for val in c[i]:
        set(val)

ans.sort()
print(ans[N - 1])

Measured memory_bytes: 13608
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;
struct Ford_Flukerson{
  ll INF = 1000000000000000000, MAX_V;
  struct edge{ll to, cap, rev;};
  vector<vector<edge>> G;
  vector<bool> used;
  Ford_Flukerson(ll n){
    MAX_V = n+1;
    G.resize(n+1);
    used.resize(n+1);
  }
  void add_edge(ll from, ll to, ll cap){
    G[from].push_back(edge{to, cap, (ll)G[to].size()});
    G[to].push_back(edge{from, 0, (ll)G[from].size() - 1});
  }
  ll dfs(ll v, ll t, ll f){
    if(v==t) return f;
    used[v] = true;
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to] && e.cap>0){
        ll d = dfs(e.to, t, min(f, e.cap));
        if(d>0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  ll max_flow(ll s, ll t){
    ll flow = 0;
    for(;;){
      for(int i=0;i<MAX_V;i++) used[i] = false;
      ll f = dfs(s, t, INF);
      if(f==0) return flow;
      flow += f;
    }
  }
};
int main(int argc, char const *argv[]) {
  ll h, w;std::cin >> h >> w;
  Ford_Flukerson D(300);
  vector<string> dat(h);
  vll s, t;
  re(i, h){
    std::cin >> dat[i];
    re(j, w){
      if(dat[i][j]=='S') {
        D.add_edge(201, i, 10000);
        D.add_edge(201, j+100, 10000);
        s = vll{i, j};
      }
      if(dat[i][j]=='T') {
        D.add_edge(i, 202, 10000);
        D.add_edge(j+100, 202, 10000);
        t = vll{i, j};
      }
      if(dat[i][j]!='.'){
        D.add_edge(i, j+100, 1);
        D.add_edge(j+100, i, 1);
      }
    }
  }
  if(s[0]==t[0]||s[1]==t[1]){
    std::cout << -1 << '\n';
    return 0;
  }
  ll ans = D.max_flow(201, 202);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1536
import itertools
import sys
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
if p == q:
    print('0')
    sys.exit(0)
num_p = num_q = 0
counter = 0
# permutations(list a) a!を表す
for pairs in itertools.permutations((range(1, n + 1))):
    lp = list(pairs)
    counter += 1
    if p == lp:
        num_p = counter
    elif q == lp:
        num_q = counter
print(abs(num_p - num_q))


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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

vector<ll> h(MAX), g[MAX];

int main()
{


    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll n, x;
    cin >> n;

    map<ll,ll> mp;

    vector<ll> ai;
    for(int i=1;i<=n;i++)
    {   
        cin >> x;
        mp[i-x]++;
        ai.push_back(x+i);
    }

    ll ans = 0;
    for(ll p: ai)
    {
        ans+= mp[p];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39916
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

const int MAX_K = 1010101;

int main()
{   
    int k;
    cin >> k;
    int cur = 0;
    rep(i,MAX_K) {
        cur = (10 * cur + 7) % k;
        if(cur == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 1e5 + 5;
ll dp[N][2];
ll go(int i, int j, int n, string &l)
{
	if (i == n)
		return 1;
	if (dp[i][j] != -1)
		return dp[i][j];
	ll ans = 0;
	if (j == 1)
	{
		if (l[i] == '1')
		{
			ans = add(ans, mul(2ll, go(i + 1, 1, n, l), MOD), MOD);
			ans = add(ans, go(i + 1, 0, n, l), MOD);
		}
		else
			ans = add(ans, go(i + 1, 1, n, l), MOD);
	}
	else
		ans = add(ans, mul(3ll, go(i + 1, 0, n, l), MOD), MOD);
	return dp[i][j] = ans;
}
void solve(int tc)
{
	string l;
	cin >> l;
	int n = l.length();
	memset(dp, -1, sizeof(dp));
	ll ans = go(0, 1, n, l);
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 8528