akhauriyash/Code-Regression huggingface dataset:
def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs *= i * pow(j, mod - 2, mod)
        combs %= mod
    return combs


def main():
    total = int(input())
    mod = 1000000007

    if total < 3:
        return 0
    ans = 0
    for lg in range(1, total // 3 + 1):
        rem = total - 3 * lg
        ans += combinations_mod(rem + lg - 1, rem, mod)
        ans %= mod
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 9100
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

int main() {
  DRI(N, T);
  int m = INF;
  int M = 0, ans = 0;
  REP(i, N) {
    DRI(p);
    m = min(m, p);
    if (p - m == M) {
      ans++;
    } else if (p - m > M) {
      ans = 1;
      M = p - m;
    }
  }
  PI(ans);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll ans=0;
const int maxn=1e5+5;
ll a[maxn*2],b[maxn*2],fa[maxn*2];
int find(int x)
{
    return (x==fa[x])?x:(fa[x]=find(fa[x]));
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<=maxn*2;i++)
        fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        fa[find(x)]=fa[find(y+maxn)];
    }
    for(int i=1;i<=maxn;i++)
    {
        a[find(i)]++;
    }
    for(int i=maxn+1;i<=maxn*2;i++)
    {
        b[find(i)]++;
    }
    for(int i=1;i<=maxn*2;i++)
    {
        ans+=a[i]*b[i];
    }
    if(ans-n<0)
        printf("0\n");
    else
        printf("%lld\n",ans-n);
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
long long A, B, K;
int main(){
  long long i, j, res=1;
  rd(K);
  rd(A);
  rd(B);
  i =min_L(A - res, K);
  K -= i;
  res += i;
  if(B-A > 2){
    res += (B-A) * (K / 2);
    K -= 2 * (K / 2);
  }
  res += K;
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// ll K, A, B;
// {
//   ll i, j, res = 1;
//   rd(K,A,B);
// 
//   i = min(A - res, K);
//   K -= i;
//   res += i;
// 
//   if(B-A > 2){
//     res += (B-A) * (K / 2);
//     K -= 2 * (K / 2);
//   }
// 
//   res += K;
// 
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n; cin >> n;
    string s; cin >> s;
    string a,b;
    a = s;
    int ans = -INF;
    rep(i,n){
        char hoge = a.back();
        b.push_back(hoge);
        a.pop_back();
        map<char,int>mp;
        rep(i,a.size())mp[a[i]]++;
        int cnt = 0;
        rep(i,b.size())if(mp[b[i]]){
            mp[b[i]] = 0;
            cnt ++;
        }
        cmax(ans, cnt);
    }
    cout << ans << endl;
}






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

const int MAXN = 302;

double dp[MAXN][MAXN][MAXN];
int N,vis[MAXN][MAXN][MAXN];

double solve(int x,int y,int z){
	
	if(vis[x][y][z]) return dp[x][y][z];
	//printf("Solving %d %d %d\n",x,y,z);
	vis[x][y][z] = 1;

	if(x == 0 && y == 0 && z == 0) return dp[x][y][z] = 0;

	int soma = x + y + z;
	double convertido = (double)soma;
	double tot = (N - soma)/convertido;
	
	//printf("Tot antes %d %d %d %d %lf\n",N - soma,x,y,z,tot);

	if(x != 0) tot += x*((solve(x-1,y,z) + 1)/convertido);
	if(y != 0) tot += y*((solve(x+1,y-1,z) + 1)/convertido);
	if(z != 0) tot += z*((solve(x,y+1,z-1) + 1)/convertido);

	//printf("Tot (%d,%d,%d) = %lf\n",x,y,z,tot);

	return dp[x][y][z] = tot;

}

int main(){

	int a[4] = {0,0,0,0};

	cin >> N;

	for(int i = 1;i<=N;i++){
		int x;
		cin >> x;
		a[x]++;
	}

	printf("%.9lf\n",solve(a[1],a[2],a[3]));

	return 0;
}

Measured memory_bytes: 165932
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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 A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<vector<ll>> next(60, vector<ll>(n));
    rep(v,0,n){
        cin >> next[0][v];
        next[0][v]--;
    }

    rep(d,0,59){
        rep(v,0,n){
            next[d+1][v] = next[d][next[d][v]];
        }
    }

    ll v = 0;
    rep(d,0,60){
        if(k & (1LL << d)) v = next[d][v];
    }

    cout << v+1 << endl;
    return 0;
}

Measured memory_bytes: 98760
#include<bits/stdc++.h>
using namespace std;
#define fr freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int arr[100000+5],dp[100000+5],n;
int main(){
	//fr
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> arr[i];
	}
	dp[2]=abs(arr[2]-arr[1]);
	for(int i=3; i<=n; i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << dp[n];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
int main(){
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vector<int> L1, L2;
    int last = -1e9;
    for(int i=0; i<N; i++){
        if(S[i] == 'o' && last+C < i){
            last = i;
            L1.push_back(i);
        }
        if(L1.size() == K) break;
    }
    int stock = 1e9;
    for(int i=N-1; i>=0; i--){
        if(S[i] == 'o' && stock >= C){
            L2.push_back(i);
            stock = 0;
        }else{
            stock++;
        }
        if(L2.size() == K) break;
    }
    reverse(L2.begin(), L2.end());
    for(int i=0; i<K; i++) if(L1[i] == L2[i]) cout << L1[i]+1 << endl;
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    ll ans1 = 0;
    ll ans2 = 0;
    double dense = 0;
    for (ll i = 0; i <= F; i+=A*100) {
        for (ll j = 0; j <= F; j+=B*100) {
            for (ll k = 0; k <= F; k+=C) {
                for (ll l = 0; l <= F; l+=D) {
                    double water = i+j;
                    double sugar = k+l;
                    double swater = water + sugar;

                    if (swater == 0 || swater > F || swater*E < (100+E)*sugar) {
                        continue;
                    }

                    double tmp = sugar/swater;
                    if (dense <= tmp) {
                        dense = tmp;
                        ans1 = swater;
                        ans2 = sugar;
                    }
                }
            }
        }
    }

    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func max(a int, b int) int {
	if (a >= b) {
		return a
	}
	return b
}

func calc(N int, M int, Q int, a []int, b []int, c []int, d []int, A []int) (r int) {
	for i:=0; i < Q; i++ {
		if (A[b[i]-1] - A[a[i]-1] == c[i]) {
			r += d[i]
		}
	}
	return
}

func solve(N int, M int, Q int, a []int, b []int, c []int, d []int, A []int) int {
	l := len(A)
	if (A[l-1] > M) {
		return 0
	}
	if (l > N) {
	//	fmt.Printf("A: %v, len: %d score: %d\n", A, l, calc(N, M, Q, a, b, c, d, A))
		return calc(N, M, Q, a, b, c, d, A)
	}

	A2 := make([]int, l)
	copy(A2, A)
	A[l-1] = A[l-1] + 1
	A2 = append(A2, A2[l-1])
	return max(solve(N, M, Q, a, b, c, d, A), solve(N, M, Q, a, b, c, d, A2))
}

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    hoge := sc.Text()
    i, e := strconv.Atoi(hoge)
    if e != nil {
        panic(e)
    }
    return i
}



func main() {
	sc.Split(bufio.ScanWords)
	N, M, Q := nextInt(), nextInt(), nextInt()
	a := make([]int, Q)
	b := make([]int, Q)
	c := make([]int, Q)
	d := make([]int, Q)
	A := []int{}
	A = append(A, 1)
	for i:=0; i < Q; i++ {
		a[i], b[i], c[i], d[i] = nextInt(), nextInt(), nextInt(), nextInt()
	}
	fmt.Println(solve(N, M, Q, a, b, c, d, A))
}



Measured memory_bytes: 6640
#include<bits/stdc++.h>
using namespace std;
char s[10000],c;
int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++)
		for(int j=i+1;j<len;j++)
			if(s[i]==s[j]){
				printf("no");
				return 0;
			}
	printf("yes");
}

Measured memory_bytes: 256
import java.io.* ;
import java.lang.reflect.Array;
import java.util.* ;
import java.math.* ;
public class Main
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while (!tokenizer.hasMoreTokens())
        {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static long nextInt() throws IOException
    {
        return Long.parseLong(next());
    }

    public static int ri() throws IOException
    {
        return (int) nextInt();
    }

    public static long rl() throws IOException
    {
        return nextInt();
    }

    public static double rd() throws NumberFormatException, IOException
    {
        return Double.parseDouble(next());
    }

    static void print_a(int[] arr)
    {
        for (int i = 0; i < arr.length; i++)
        {
            print(arr[i] + " ");
        }
        println();
    }

    public static int[] ria(int n) throws IOException
    {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = ri();
        }
        return a;
    }

    public static long[] rla(int n) throws IOException
    {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = rl();
        }
        return a;
    }

    public static int p(int i)
    {
        return (int) Math.pow(2, i);
    }

    static PrintWriter writer;

    static void outit(OutputStream outputStream)
    {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    static void print(Object... objects)
    {
        for (int i = 0; i < objects.length; i++)
        {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    static void println(Object... objects)
    {
        print(objects);
        writer.println();
    }

    static void close()
    {
        writer.close();
    }

    static void flush()
    {
        writer.flush();
    }

    public static void main(String[] args) throws IOException
    {
        init(System.in);
        outit(System.out);
//        int t = (int) nextInt();
//        for (int i = 0; i < t; i++)
        output();
        flush();
        close();
    }
    static ArrayList<Integer> [] ar;
    static ArrayList<Integer> [] fg ;
    static long [][] cost ;
    static boolean [] visited ;
    public static void output() throws IOException
    {
        int n = ri() ;
        int [] a = new int[n] ;
        for (int i = 0; i <n ; i++)
        {
            a[i] = ri() ;
        }
        Arrays.sort(a);
        println(a[n-1]-a[0]) ;
    }
}

Measured memory_bytes: 21076
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;

  if (S == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  };

  return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int n;cin>>n;
    int r[n];
    rep(i,0,n)cin>>r[i];
    vector<int> rating={399,799,1199,1599,1999,2399,2799,3199,4800};
    int id[9]={0};
    rep(i,0,n){
        id[lower_bound(all(rating),r[i])-rating.begin()]++;
    }
    int mi=0;
    rep(i,0,8)if(id[i]!=0)mi++;
    mi==0?cout<<1<<" "<<id[8]:cout<<mi<<" "<<mi+id[8];

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
# Dice III
# 2018/11/17, 2019/1/16
from collections import Counter
 
class Dice:
    def __init__(self, *num):
        if len(num) != 6:
            raise ValueError("6!")
        self.numbers = num
 
    def east(self):
        index = (3, 1, 0, 5, 4, 2)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def west(self):
        index = (2, 1, 5, 0, 4, 3)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def south(self):
        index = (4, 0, 2, 3, 5, 1)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def north(self):
        index = (1, 5, 2, 3, 0, 4)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    def rot_top(self):
        """topを変えないように時計周りにくるくる回す"""
        index = (0, 2, 4, 1, 3, 5)
        self.numbers = tuple((self.numbers[i] for i in index))
 
    @property
    def top(self):
        return self.numbers[0]
 
    @property
    def front(self):
        return self.numbers[1]
 
    @property
    def right(self):
        return self.numbers[2]
 
    def __repr__(self):
        return "Dice(" + ", ".join([str(i) for i in self.numbers]) + ")"
 
 
    def align_top_and_front(self, tmp_dice):
        # topを一番レアいやつにする
        rarest = Counter(self.numbers).most_common()[-1][0]
        for i in range(4):
            if self.top == rarest:
                break
            self.east()
        for i in range(4):
            if self.top == rarest:
                break
            self.north()
 
        # topが合うまで回す
        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.east()
 
        for i in range(4):
            if self.top == tmp_dice.top:
                break
            tmp_dice.north()
 
        # frontを合わせる
        for i in range(4):
            if self.front == tmp_dice.front:
                break
            tmp_dice.rot_top()
        return tmp_dice
 
 
    def align(self, other_dice):
        tmp = Dice(*other_dice.numbers)
        tmp = self.align_top_and_front(tmp)
        #print(self.numbers)
        #print(tmp.numbers)
        if self.numbers == tmp.numbers:
            print("Yes")
        else:
            print("No")
 
 
def main():
    num = [int(i) for i in input().split()]
    dice = Dice(*num)
 
    num = [int(i) for i in input().split()]
    other_dice = Dice(*num)
 
    Dice.align(dice, other_dice)
 
if __name__ == "__main__":
    main()


Measured memory_bytes: 6028
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int i;
  int n,sum=0;
  cin>>n;
  vector<int> a(n+1),b(n),c(n-1);
  for(i=0;i<n;++i)cin>>a.at(i);
  for(i=0;i<n;++i)cin>>b.at(i);
  for(i=0;i<n-1;++i)cin>>c.at(i);
  for(i=0;i<n;++i){
    sum+=b.at(a.at(i)-1);
    if(a.at(i+1)-a.at(i)==1)
      sum+=c.at(a.at(i)-1);
   // cout<<sum<<" ";
  }
  cout<<sum<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N;
	cin >> N;
	int tmp=0, num = 0;
	string ans = "Yes";
	REP(i, 0, N){
		cin >> num;
		if(num > tmp) tmp = num-1;
		else if(tmp > num) {
			ans = "No";
			break;
		}
	}
	cout << ans;

}


Measured memory_bytes: 256
P, Q, R = map(int, input().split())

if (P + Q) <= (R + Q) and (P + Q) <= (R + P):
  print(P + Q)
elif (R + Q) <= (P + Q) and (R + Q) <= (R + P):
  print(R + Q)
elif (R + P) <= (P + Q) and (R + P) <= (P + Q):
  print(R + P)

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N, M, dp[102][102];
char ch[102][102];

int main() {
 scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) scanf("%s", ch[i] + 1);
  dp[1][1] = (ch[1][1] == '#');
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (i > 1 || j > 1) dp[i][j] = 0x3f3f3f3f;
      if (i > 1)
        dp[i][j] = min(dp[i][j],
                       dp[i - 1][j] + (ch[i][j] == '#' && ch[i - 1][j] == '.'));
      if (j > 1)
        dp[i][j] = min(dp[i][j],
                       dp[i][j - 1] + (ch[i][j] == '#' && ch[i][j - 1] == '.'));
    }
  }
  printf("%d\n", dp[N][M]);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    ll a,b;cin>>a>>b;
    ll x = a * b;

    if (a < b)
    {
        ll tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }

    cout<<x/b<<endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mxN = 1e6 + 50;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int pos[mxN], cnt[mxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	set<int> st;
	rep(i, n) cin >> a[i], cnt[a[i]]++, st.insert(a[i]);
	vi b(all(st));
	rep(i, b.size()){
		for(int j = b[i]; j < mxN; j += b[i]) pos[j] += cnt[b[i]];
	}
	int ans = 0;
	rep(i, n) ans += (pos[a[i]] == 1);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 21140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127C
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

            var n = nums[0];
            var m = nums[1];

            var min = int.MinValue;
            var max = n;

            foreach (var _ in Enumerable.Range(0, m))
            {
                nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

                min = Math.Max(min, nums[0]);
                max = Math.Min(max, nums[1]);
            }

            Console.WriteLine(Math.Max(0, max - min + 1));

        }
    }
}


Measured memory_bytes: 17360
N = int(input())
A = list(map(int, input().split()))

def dev2(n):
    cnt = 0
    while True:
        if n % 2 != 0:
            return cnt
        cnt += 1
        n //= 2

ans = dev2(A[0])
for i in range(1, N):
    ans = min(ans, dev2(A[i]))
    if ans == 0:
        break

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
int a[100000];
int main(){
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 0;
  while(true){
    for(int i = 0; i < n; i++){
      if(a[i] % 2 != 0){
        cout << ans << endl;
        return 0;
      }
    }
    for(int i = 0; i < n; i++){
      a[i] /= 2;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int numOfSatisfy(vector<int> &v){
	if (v.empty()) return -1;
	int count = 0;
	for(int i=0; i<v.size();){
		if(v[i]%2 == 1){
			count +=1 ;
		}
		i += 2;
	}
	return count;
}


int main(){
	int N;
	cin >> N;
	vector<int> a;
	for (int i=0; i<N; i++){
		int temp;
		cin >> temp;
		a.push_back(temp);
	}

	cout << numOfSatisfy(a);

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int h=0,t=b.size()-1;
	while(h<a.size())
	{
		if(a[h]!=b[t])
		{
			cout<<"NO";return 0;
		}
		h++;t--;
	}
	cout<<"YES";return 0;
}

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

signed main(){
  int n,m,ans=1e9;
  cin>>n>>m;
  int p[n],c[n];
  r(i,n)cin>>p[i]>>c[i];
  for(int i=0;i<(1<<n);i++){
    int s=0,sco=0;
    r(j,n)if(i&(1<<j))s+=p[j],sco+=c[j]+(100*(j+1))*p[j];
    if(sco>=m){
      ans=min(ans,s);
      continue;
    }
    vector<int>v;
    r(j,n)if(!(i&(1<<j))){
      r(k,p[j])v.push_back(100*(j+1));
    }
    sort(v.begin(),v.end(),greater<int>());
    r(j,v.size()){
      s++;
      sco+=v[j];
      if(sco>=m)break;
    }
    ans=min(ans,s);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def addition_and_multiplication(N: int, K: int)->int:
    min_d = float('inf')
    for i in range(1 << N):
        d = 1
        # i のビットが立っているところでは 2 倍にする。
        # それ以外では K をたす。
        for _ in range(N):
            if i & 1:
                d = d * 2
            else:
                d = d + K
            i >>= 1
        min_d = min(d, min_d)
    return min_d


if __name__ == "__main__":
    N = int(input())
    K = int(input())
    ans = addition_and_multiplication(N, K)
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cassert>
#include <random>
#include <time.h>
#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define re return
#define mp make_pair

using namespace std;

typedef long long ll;

const double pi = 3.14159265;
const ll mod = 1e9 + 7;
const ll N = 3e5 + 5;
const int OMG = 9e6 + 5;
const ll P0 = 281;
const ll P1 = 257;


int main()
{
    //freopen("ladder.in ", "r", stdin);
    //freopen("OMOMOMMG.txt", "w", stdout);
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(all(a));
    reverse(all(a));
    ll an = 0;
    for (int i = k; i < n; i++)
        an += a[i];
    cout << an;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
int gcf(int a, int b) {return (b == 0) ?  a : gcf(b, a%b);}
ll gcf(ll a, ll b) {return (b == 0) ? a : gcf(b, a%b);} 
int lcm(int a, int b) {return (a*b)/gcf(a, b);}
ll lcm(ll a, ll b) {return (a*b)/gcf(a, b);}
void Yes() {printf("Yes");}
void No() {printf("No");}

void solve() {
    string s; cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') Yes();
    else No();
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
int main()
{
  int a,b,c,i,n=0;
  scanf("%d%d%d",&a,&b,&c);
  i=a;
  while(i<=b)
    {
      if(c%i==0)n++;
      i++;
    }
  printf("%d\n",n);

  return 0;

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    if(s=="Sunny") cout << "Cloudy" << endl;
    else if(s=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

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

using namespace std;

int main(){
	int n, sol = 0;
	cin >> n;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int u = 1; u <= n; ++u){
				sol += __gcd(i,__gcd(j,u));
			}
		}
	}
	cout << sol << '\n';
}


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

using namespace std;

void solve() {
  int a = 0, b = 0, c;
  bool f = true;
  for (int i = 0; i < 10; ++i) {
    cin >> c;
    if (c < a) f = false;
    else if (c < b) a = c;
    else b = c;
  }
  cout << (f ? "YES" : "NO") << endl;
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) solve();
}

Measured memory_bytes: 3100
s = input()
t = input()

l = len(t)
n = len(s) - len(t)

def count_diffs(lhs, rhs):
    return len(list(filter(lambda t: t[0] != t[1], zip(lhs, rhs))))

min_diff = l

for i in range(n):
    diff = count_diffs(s[i : i + l], t)

    if diff < min_diff:
        min_diff = diff

if n != 0:
    print(min_diff)

else:
    print(count_diffs(s, t))


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  string s;
  cin >> s;
  ll count = 0;
  rep(i,4){
    if(s[i]=='+'){
      count++;
    }
    else{
      count--;
    }
  }
  print(count);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int n, v;
   int A[150];
   int i = 0,
	   j = 0,
	   k = 0;

   scanf("%d", &n);
   while (i < n) {
      scanf("%d", &A[i]);
      i++;
   }

   for (i = 0; i < n; ++i) {
      v = A[i];
	  j = i - 1;
      while (j >= 0 && A[j] > v) {
         A[j + 1] = A[j];
         --j;
      }
      A[j + 1] = v;
      for (k = 0; k < n; ++k) {
         printf("%d", A[k]);
		 if (k != n - 1)
			 putchar(' ');
	  }
	  putchar('\n');
   }
   return 0;
}

Measured memory_bytes: 1748
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    while(cnt!=10000&&a%2==0&&b%2==0&&c%2==0){
        int x=a,y=b,z=c;
        a=y/2+z/2;
        b=x/2+z/2;
        c=x/2+y/2;
        cnt++;
    }
    if(cnt==10000)cout<<-1<<endl;
    else cout<<cnt<<endl;
    return 0;
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

using ll = long long;

const int MAXN = 2010;
int N, K;
int A[MAXN];

num c2(ll n) {
	return num(n) * (n-1) / 2;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	num ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			if (A[i] > A[j]) {
				ans += K;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (A[j] < A[i]) {
				ans += c2(K);
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<P> v(N);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    v[i] = P(A, B);
  }

  sort(v.begin(), v.end());
  long long ans = 0;
  int cnt = 0, index = 0;
  for (int i = 0; i < M; i++) {
    ans += v[index].first;
    cnt++;
    if (cnt >= v[index].second) {
      index++;
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a;
    vpi x;
    forn(i,5){
        cin>>a;
        int diff = (((a+9)/10)*10) - a;
        //cout<<diff<<" "<<a<<endl;
        x.pb(mp(diff,a));
    }
    //for(int i=0;i<5;i++)    cout<<x[i].fi<<" "<<x[i].se<<endl;
    sort(x.begin(), x.end());
    //for(int i=0;i<5;i++)    cout<<x[i].fi<<" "<<x[i].se<<endl;
    int sum =0 ;
    for(int i=0;i<5;i++){
        if(i==4)
            sum += x[i].se;
        else
            sum += (x[i].fi + x[i].se);
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 256
import heapq
def dijkstra(s, n, g, d): # s: start, n: |V|, g; glaph 
    INF = 10**18
    d[s] = 0
    que = [] # (a,b): a... shortest dist, b... v
    heapq.heappush(que, (0, s))

    while que:
        dist, v = heapq.heappop(que)
        if d[v] < dist: continue # if v has been already used -> continue
        for next_v, cost in g[v]:
            if d[next_v] > d[v] + cost:
                d[next_v] = d[v] + cost
                heapq.heappush(que, (d[next_v], next_v))
    return d


def main():
    n,m,s = map(int, input().split())
    # g = [ [] for _ in range(n*2501+1)]
    g = {}
    dist = {}
    for i in range(n):
        for j in range(2501):
            g[(i,j)] = []
            dist[(i,j)] = 10**18
    for _ in range(m):
        u,v,a,b = map(int, input().split())
        u-=1
        v-=1
        for j in range(2501):
            if j < a: continue
            g[(u,j)].append(((v,j-a),b))
            g[(v,j)].append(((u,j-a),b))
            # g[u*2501+j].append((v*2501+j-a,b))
            # g[v*2501+j].append((u*2501+j-a,b))

    for i in range(n):
        c,d = map(int, input().split())
        for j in range(2501):
            maxc = min(2500,j+c)
            g[(i,j)].append(((i,maxc), d))

    sc = min(2500,s)
    s = (0,sc)
    dist = dijkstra(s, n*2501+1, g, dist)
    # print(dist)
    for i in range(1,n):
        ans = 10**18
        for j in range(2501):
            ans = min(ans, dist[(i,j)])
        print(ans)

if __name__ == "__main__":
    main()

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

template <class T, class U>
inline bool chmin(T& t, const U& f) { return t > f ? t = f, true : false; }

template <class T, class U>
inline bool chmax(T& t, const U& f) { return t < f ? t = f, true : false; }

const int X = 1 << 30;

int solve(int N, const vector<int>& a) {
    int lo = -X + 1, hi = X - 1;
    rep(i, N) {
        if (i & 1) {
            if (a[i] != X) {
                if ((a[i - 1] != X && a[i - 1] >= a[i]) ||
                    (i < N - 1 && a[i + 1] != X && a[i] <= a[i + 1])) throw "none";
                if ((a[i - 1] == X) || (i < N - 1 && a[i + 1] == X)) chmin(hi, a[i] - 1);
            }
            else {
                if ((a[i - 1] == X) || (i < N - 1 && a[i + 1] == X)) throw "none";
                if (a[i - 1] != X) chmax(lo, a[i - 1] + 1);
                if (i < N - 1 && a[i + 1] != X) chmax(lo, a[i + 1] + 1);
            }
        }
        else {
            if (a[i] != X) {
                if ((i > 0 && a[i - 1] != X && a[i - 1] <= a[i]) ||
                    (i < N - 1 && a[i + 1] != X && a[i] >= a[i + 1])) throw "none";
                if ((i > 0 && a[i - 1] == X) || (i < N - 1 && a[i + 1] == X)) chmax(lo, a[i] + 1);
            }
            else {
                if ((i > 0 && a[i - 1] == X) || (i < N - 1 && a[i + 1] == X)) throw "none";
                if (i > 0 && a[i - 1] != X) chmin(hi, a[i - 1] - 1);
                if (i < N - 1 && a[i + 1] != X) chmin(hi, a[i + 1] - 1);
            }
        }
    }
    if (lo != hi) throw lo < hi ? "ambiguous" : "none";
    return lo;
}

int main() {
    for (int N; cin >> N, N;) {
        vector<int> a(N);
        for (int& e : a) {
            string s; cin >> s;
            e = s == "x" ? X : stoi(s);
        }
        try { cout << solve(N, a) << endl; }
        catch (char const* err) { cout << err << endl; }
    }
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> H(N);
    int max_cnt = 0;
    int cnt = 0;
    rep(i, N)
    {
        cin >> H[i];
        if (i > 0)
        {
            if (H[i - 1] - H[i] >= 0)
            {
                cnt++;
            }
            else
            {
                max_cnt = max(max_cnt, cnt);
                cnt = 0;
            }
        }
    }
    max_cnt = max(max_cnt, cnt);

    cout << max_cnt << endl;

    //system("pause");
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, cnt[100][100];
vector <pair <int, int> > v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        string s;
        cin >> s;
        if(s.back() == '.') s.pop_back();
        for(int j = 0 ; j < 9 ; j++){
            auto it = find(s.begin(), s.end(), '.');
            if(it == s.end()){
                s += '0';
            }
            else{
                int idx = it - s.begin();
                swap(s[idx], s[idx + 1]);
                if(s.back() == '.') s.pop_back();
            }
        }
        ll a = 0;
        for(auto &i : s){
            a = 10 * a + i - '0';
        }
        int twos = 0, fives = 0;
        while(a % 2 == 0){
            twos++;
            a /= 2;
        }
        while(a % 5 == 0){
            fives++;
            a /= 5;
        }
        twos = min(twos, 18);
        fives = min(fives, 18);
        v.push_back(make_pair(twos, fives));
    }
    ll ans = 0;
    for(int i = 0 ; i < n ; i++){
        int x = v[i].first, y = v[i].second;
        for(int g = 0 ; g <= 18 ; g++){
            for(int h = 0 ; h <= 18 ; h++){
                if(min(x + g, y + h) >= 18){
                    ans += cnt[g][h];
                }
            }
        }
        cnt[x][y]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5332
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A,B;
std::string S;

int main()
{
	in>>A>>B>>S;
	rep(i,S.length())
	{
		if(i<A&&S[i]=='-')
		{
			out<<"No"<<std::endl;
			return 0;
		}
		if(i==A&&S[i]!='-')
		{
			out<<"No"<<std::endl;
			return 0;
		}
		if(i>A&&S[i]=='-')
		{
			out<<"No"<<std::endl;
			return 0;
		}
	}
	out<<"Yes"<<std::endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

ll n;
map<ll, int> mp;

int solve(ll x)
{
    if (mp.count(x) > 0)
        return mp[x];
    else
        return mp[x] = (0LL + solve(x >> 1) + solve((x - 1) >> 1) + solve((x - 2) >> 1)) % mod;
}

int main()
{
    mp[0] = 1, mp[1] = 2;
    scanf("%lld", &n), printf("%d\n", solve(n));
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 100010
int n, k, a[MAXN];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int g;; k ^= 1) {
		int count = 0;
		for (int i = 1; i <= n; i++) count += a[i] & 1;
		if ((n - count) & 1) {
			return puts(k ? "Second" : "First"), 0;
		}
		if (count >= 2) {
			return puts(k ? "First" : "Second"), 0;
		}
		g = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] & 1) {
				if (a[i] == 1) return puts(k ? "First" : "Second"), 0;
				--a[i];
			}
			g = gcd(a[i], g);
		}
		for (int i = 1; i <= n; i++) a[i] /= g;
	}
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using std::vector;
using std::cin;
using std::cout;
using std::max;
using std::unordered_map;

struct Item {
  int w;
  int v;
  Item() {}
  Item(int w, int v) : w(w), v(v) {}
};

class Solution {
  vector<vector<int>> memo;
public:
  Solution(int w, int n) : memo(w + 1, vector<int>(n + 1, -1)) {}
  int maxv(vector<Item> &items, int w, int offset = 0) {
    if (memo[w][offset] < 0) {
      auto &item = items[offset];
      if (offset == items.size()) {
        memo[w][offset] = 0;
      } else if (item.w > w){
        memo[w][offset] = maxv(items, w, offset + 1);
      } else {
        memo[w][offset] = max(
            item.v + maxv(items, w - item.w, offset + 1),
            maxv(items, w, offset + 1));
      }
    }

    return memo[w][offset];
  }
};

int main(int argc, const char *argv[])
{
  int n, w;
  cin >> n >> w;

  vector<Item> items(n);
  for (int i = 0; i < n; i++) {
    cin >> items[i].v >> items[i].w;
  }
  
  Solution s(w, n);
  cout << s.maxv(items, w) << "\n";

  return 0;
}


Measured memory_bytes: 7100
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
diff = max(h)
for i in range(0, len(h)-K+1):
  if diff > h[i+K-1]-h[i]:
    diff = h[i+K-1]-h[i]
print(diff)

Measured memory_bytes: 7384
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n=int(input())
l = make_divisors(n)
if len(l)%2==0:
    print((l[len(l)//2-1]-1)+(l[len(l)//2]-1))
else:
    print((l[len(l)//2]-1)+(l[len(l)//2]-1))

Measured memory_bytes: 3268