akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int SN[30] = {},i=28,n;
	while (i--) fscanf(stdin, "%d", &n), SN[n - 1] = 1;
	for (i = 0; i < 30; i++) if (!SN[i]) P(d, i + 1);
	return 0;
}

Measured memory_bytes: 600
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def dfs_order(G, root=1):
    parent = [0] * (N + 1)
    order = []
    stack = [root]
    while stack:
        x = stack.pop()
        order.append(x)
        for y in G[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            stack.append(y)
    return parent, order

N, *A = map(int, read().split())
G = [[] for _ in range(N + 1)]
for i, x in enumerate(A, 2):
    G[x].append(i)
    G[i].append(x)

parent, order = dfs_order(G)

dp = [0] * (N + 1)
for v in order[::-1]:
    p = parent[v]
    nums = [dp[w] for w in G[v] if w != p]
    if not nums:
        continue
    nums.sort()
    n = len(nums)
    for i in range(n):
        nums[i] += n - i
    dp[v] = max(nums)

print(dp[1])

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

int main() {
    string s;

    cin >> s;

    bool flag = true;
    for(int i = 0 ; i < s.length()-1 ; i = i+2){
        
        if(s.at(i) != 'h' || s.at(i+1) != 'i'){
            flag = false;
        }
    }

    if(s.length() % 2 != 0) flag = false;

    if(flag) cout << "Yes" << endl;
    else     cout << "No"  << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  cout << "Christmas";

  REP (i, 25 - d) {
    cout << " Eve";
  }

  cout << endl;
}


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

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

using namespace std;

int main(){
	ll n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<ll> xi(n);
	vector<ll> yi(m);
	REP(i, n){cin >> xi[i];}
	REP(i, m){cin >> yi[i];}
	ll max_x = *max_element(xi.begin(), xi.end());
	ll min_y = *min_element(yi.begin(), yi.end());
	if (x < max_x && max_x < min_y && min_y <= y){
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}
}


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

int main() {
    string S, T;
    cin >> S >> T;
    bool nofl = false;
    int s_rp[26], t_rp[26];
    fill_n(s_rp, 26, -1);
    fill_n(t_rp, 26, -1);
    for(int i = 0; i < S.length(); ++i) {
        int sc = S[i] - 'a', tc = T[i] - 'a';
        if(s_rp[sc] != -1 && s_rp[sc] != tc) {
            nofl = true;
            break;
        }
        if(t_rp[tc] != -1 && t_rp[tc] != sc) {
            nofl = true;
            break;
        }
        s_rp[sc] = tc;
        t_rp[tc] = sc;
    }
    cout << (nofl ? "No" : "Yes") << endl;
    return 0;
}


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

int main() {
    vector<int> v;
    int i, num, count=0;
    for (i=0; i < 3; i++) {
        cin >> num;
        v.push_back(num);
    }
    sort(v.begin(), v.end());
    
    for (i=0; i < 2; i++) {
        count += abs(v[i]-v[i+1]);
    }
    cout << count << endl;
    return 0;
}

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

public class Main {

     static Scanner scanner;

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

         int H=gi();
         int W=gi();
         String[] S=new String[H];
         int[][][] c=new int[2][H][W];

         for(int i=0; i<H;i++) {
        	 S[i]=gs();
         }

         long max=0;

         for(int i=0; i<H;i++) {
        	 for(int j=0; j<W;j++) {
        	     char m=S[i].charAt(j);
        	     if(m=='.') {
        	    	 if(c[0][i][j]==0) {
        	    		 int n=1;
        		         for(int k=i+1; k<H;k++) {
                             char m2=S[k].charAt(j);
                             if(m2=='.') {
                            	 n++;
                             } else {
                            	 break;
                             }
                         }
        		         for(int k=i; k<i+n;k++) {
                             c[0][k][j]=n;
                         }
        	    	 }
        	    	 if(c[1][i][j]==0) {
        	    		 int n=1;
        		         for(int k=j+1; k<W;k++) {
                             char m2=S[i].charAt(k);
                             if(m2=='.') {
                            	 n++;
                             } else {
                            	 break;
                             }
                         }
        		         for(int k=j; k<j+n;k++) {
                             c[1][i][k]=n;
                         }
        	    	 }
        	    	 max=Math.max(max, c[0][i][j]+c[1][i][j]-1);
        	     }
             }
         }

         System.out.print(max);
     }

     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

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

using namespace std;

double n;

double cnt = 0;

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        if (i % 2 == 1)cnt ++;
    }
    cout << fixed << setprecision (9) << cnt / n;
}


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

int main(){
  int N;
  cin>>N;
  string s,t;
  cin>>s>>t;
  if(s==t){
    cout<<N<<endl;
    return 0;
  }
  int temp=0;
  for (int i=0;i<N;i++){
    if(s.substr(N-1-i)==t.substr(0,i+1)){
      temp=max(temp,i+1);
    }
  }
  //cout <<N<<" "<<count<<endl;
  cout<<N*2-temp<<endl;
  return 0;
}

  
       
       

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        mut v: [usize; n]
    }
    v.sort();
    let mut l = 0;
    let mut r = 200001;
    while l + 1 < r {
        let x = (l + r) / 2;
        let mut c = 0;
        for i in 0..n {
            if v[i] + v[0] >= x {
                c += n;
                continue;
            }
            let mut l2 = 0;
            let mut r2 = n;
            while l2 + 1 < r2 {
                let m2 = (l2 + r2) / 2;
                if v[i] + v[m2] >= x {
                    r2 = m2;
                } else {
                    l2 = m2;
                }
            }
            c += n - r2;
        }
        if c >= m {
            l = x;
        } else {
            r = x;
        }
    }
    let mut ac = v.clone();
    ac.push(0);
    for i in (0..n).rev() {
        ac[i] += ac[i + 1];
    }
    let mut ans = 0;
    let mut c = 0;
    for i in 0..n {
        if v[i] + v[0] >= l {
            c += n;
            ans += n * v[i] + ac[0];
            continue;
        }
        let mut l2 = 0;
        let mut r2 = n;
        while l2 + 1 < r2 {
            let m2 = (l2 + r2) / 2;
            if v[i] + v[m2] >= l {
                r2 = m2;
            } else {
                l2 = m2;
            }
        }
        c += n - r2;
        ans += (n - r2) * v[i] + ac[r2];
    }
    ans -= l * (c - m);
    println!("{}", ans);
}


Measured memory_bytes: 6396
def function(n)
	hash = Hash.new
	(0...n).each do |i|
		s = gets.chomp
		if hash.has_key?(s)
			hash[s] = hash[s] + 1
		else
			hash[s] = 1
		end
	end
	max = hash.max do |a, b|
		a[1] <=> b[1]
	end
	hash = hash.select { |_, v| v == max[1] }
	hash = hash.sort { |a, b| a[0] <=> b[0] }
	hash.map { |k, _| k }
end

n = gets.chomp.to_i
puts function(n)


Measured memory_bytes: 51560
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            x+=1
y=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            y+=1
cnt=(x*k)+(k*(k-1)//2*y)
print(cnt%(10**9+7))


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <queue>
#include <vector>

#define rep(i,min,max) for(int i=min;i<max;i++)
#define rrep(i,min,max) for(int i=max;i>=min;i--)

using namespace std;

int main(){
  char b;
  
  cin >> b;
  if(b == 'A')
    cout << 'T' << endl;
  else if(b == 'T')
    cout << 'A' << endl;
  else if(b == 'C')
    cout << 'G' << endl;
  else if(b == 'G')
    cout << 'C' << endl;
  return 0;
}



Measured memory_bytes: 256
H, W = map(int, input().split())
# p1
if H % 3 == 0 or W % 3 == 0:
    sq1 = 0
else:
    sq1 = min((H // 3 + 1 - H // 3) * W, (W // 3 + 1 - W // 3) * H)
# p2
sq2 = 10 ** 12
for h in range(1, H + 1):
    sq21 = h * W
    sq22 = (H - h) * -(-W // 2)
    sq23 = (H - h) * (W // 2)
    sq2 = min(sq2, max(sq21, sq22, sq23) - min(sq21, sq22, sq23))
# p3
sq3 = 10 ** 12
for w in range(1, W + 1):
    sq31 = w * H
    sq32 = (W - w) * -(-H // 2)
    sq33 = (W - w) * (H // 2)
    sq3 = min(sq3, max(sq31, sq32, sq33) - min(sq31, sq32, sq33))
ans = min(sq1, sq2, sq3)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
const int N = 1e5 + 7;

int n, a[N];

int main() {
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	int s = 0;
	rep(i, 1, n - 1) {
		s += a[i];
	}
	a[n] < s ? puts("Yes") : puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

// double exp(int p){

// }

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,0,n-1)cin >> p[i];
    vector<double> e(n);
    double ans = 0.0;

    rep(i,0,n-1){
        ans += (double)(p[i]+1)/2;
        if(i>=k)ans -= (double)(p[i-k]+1)/2;
        e[i] = ans;
    }
    rep(i,0,n-1){
        ans = max(ans,e[i]);
    }

    // cout << ans << endl;
 printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;

vector<string> bubble(vector<string> &a) {
    rep(i, 0, n) {
        eper(j, n-1, i+1) {
            if (a[j][1] < a[j-1][1]) 
                swap(a[j], a[j-1]);
        }
    }
    return a;
}

vector<string> selection(vector<string> &a) {
    rep(i, 0, n) {
        int minj = i;
        rep(j, i, n) {
            if (a[j][1] < a[minj][1])
                minj = j;
        }
        swap(a[i], a[minj]);
    }
    return a;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vector<string> a(n), b(n);
    rep(i, 0, n) {
        cin >> a[i];
        b[i] = a[i];
    }
    vector<string> bs = bubble(a);
    vector<string> ss = selection(b);
    bool flag = true;
    rep(i, 0, n) {
        if (bs[i] != ss[i]) flag = false;
    }
    rep(i, 0, bs.size()) cout << bs[i] << (i != bs.size()-1 ? " " : "\n");
    cout << "Stable" << endl;
    rep(i, 0, ss.size()) cout << ss[i] << (i != ss.size()-1 ? " " : "\n"); 
    if (flag) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    return 0;
}


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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			exit(0);
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int tl[200020],tr[200010];
int*l=tl+100010,*r=tr+100010;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n){
		int x,y;
		scanf("%d%d",&x,&y);
		l[x]++;
		r[y]++;
	}
	l[0]++;r[0]++;
	for(int i=100005;i>=-100005;i--)l[i-1]+=l[i];
	rep(i,-100005,100005)r[i+1]+=r[i];
	
	//小区間[i,i+1]を通る回数は、iより左にある区間の個数とi+1より右にある区間の個数のmin
	ll ans=0;
	rep(i,-100005,100005)ans+=min(r[i],l[i+1]);
	printf("%lld",ans*2);
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    string str;
    cin>>str;
    int red=0,blue=0;
    for(int i=0;i<n;i++){
        if( str[i] == 'R' ) red++;
        else blue++;
    }
    if( red > blue){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val B = listOfInt()
    val A = IntArray(N)
    A[0] = B[0]
    for (n in 1 until N - 1) {
        A[n] = Math.min(B[n - 1], B[n])
    }
    A[N - 1] = B[N - 2]
    var ans = A.sum()
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 36276
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	void set(int arg_state,int arg_station,int arg_total_time,int arg_eat_num){
		state = arg_state;
		station = arg_station;
		total_time = arg_total_time;
		eat_num = arg_eat_num;
	}
	int state,station,total_time,eat_num;
};

int N,M,L,start,TIME_LIMIT,cost[301][301];
int POW[17],eat_time[301];
int** min_Time;

void func(){

	for(int i = 1; i <= N; i++){
		for(int k = 1; k <= N; k++){
			if(i != k)cost[i][k] = BIG_NUM;
			else{
				cost[i][k] = 0;
			}
		}
	}

	int from,to,tmp_cost;

	for(int i = 0; i < M; i++){
		scanf("%d %d %d",&from,&to,&tmp_cost);
		cost[from][to] = tmp_cost;
		cost[to][from] = tmp_cost;
	}

	vector<int> V;

	int left,right;

	for(int i = 0; i < L; i++){
		scanf("%d %d",&left,&right);
		eat_time[left] = right;
		V.push_back(left);
	}

	for(int mid = 1; mid <= N; mid++){
		for(int st = 1; st <= N; st++){
			if(cost[st][mid] == BIG_NUM)continue;
			for(int gl = 1; gl <= N; gl++){
				if(cost[mid][gl] == BIG_NUM)continue;
				cost[st][gl] = min(cost[st][gl],cost[st][mid]+cost[mid][gl]);
			}
		}
	}

	int limit = POW[L];

	for(int i = 1; i <= N; i++){
		for(int k = 0; k < limit; k++)min_Time[i][k] = BIG_NUM;
	}

	Info first;
	first.station = start;
	first.state = 0;
	first.total_time = 0;
	first.eat_num = 0;

	min_Time[start][0] = 0;

	int ans = 0,next_station,next_state;

	queue<Info> Q;
	Q.push(first);

	while(!Q.empty()){

		if(Q.front().state == limit-1){
			ans = L;
			break;
		}else if(Q.front().total_time > min_Time[Q.front().station][Q.front().state]){
			Q.pop();
		}else{
			for(int loop = 0; loop < L; loop++){

				if(Q.front().state & (1 << loop)){
					//Do nothing
				}else{
					next_station = V[loop];

					if(cost[Q.front().station][next_station] != BIG_NUM && cost[next_station][start] != BIG_NUM &&
							Q.front().total_time+cost[Q.front().station][next_station]+eat_time[V[loop]] + cost[next_station][start] <= TIME_LIMIT){

						next_state = Q.front().state + POW[loop];
						if(min_Time[next_station][next_state] > Q.front().total_time+cost[Q.front().station][next_station]+eat_time[V[loop]]){
							min_Time[next_station][next_state] = Q.front().total_time+cost[Q.front().station][next_station]+eat_time[V[loop]];
							ans = max(ans,Q.front().eat_num+1);
							Info new_info;
							new_info.set(next_state,next_station,min_Time[next_station][next_state],Q.front().eat_num+1);

							Q.push(new_info);
						}
					}
				}
			}
			Q.pop();
		}
	}

	printf("%d\n",ans);
}

int main(){

	for(int i = 0; i <= 16; i++)POW[i] = pow(2,i);

	min_Time = new int*[301];
	for(int i = 1; i <= 300; i++){
		min_Time[i] = new int[POW[16]];
	}

	while(true){
		scanf("%d %d %d %d %d",&N,&M,&L,&start,&TIME_LIMIT);
		if(N == 0 && M == 0 && L == 0 && start == 0 && TIME_LIMIT == 0)break;

		func();
	}
	return 0;
}

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

const int N = 10000;
const int INFTY = (1 << 29);
int n, e;
vector<int> G[N];
int indeg[N];
bool visited[N];
list<int> out;

void bfs(int u) {
	queue<int> q;
	q.push(u);
 
	visited[u] = true;
    int s;
    while( !q.empty() ) {
    	s = q.front(); q.pop();
    	out.push_back(s);
    	for( int i = 0; i < G[s].size(); i++) {
    		    int v = G[s][i];
    			indeg[v]--;
    			if(indeg[v] == 0 )
    			{
    				visited[v] = true;
    				q.push(v);
    			}
   			
    		
    	}


    }
    
}
void tsort() {
	for( int i = 0; i < n; i++ ) indeg[i]= 0;

	for( int i = 0; i < n; i++ ) {
		
		for( int j = 0; j < G[i].size(); j++ ) {
           indeg[G[i][j]] ++;
		}
	}

	for( int u = 0; u < n; u++ ) {
		if( indeg[u] == 0 && !visited[u] ) bfs(u);
	}

	for( list<int>::iterator it = out.begin(); it != out.end(); it++ ) {
		cout << *it << endl;
	}
}
int main() {
	int u, k, v;
	cin>> n >> e;
    
    for( int i = 0; i < n; i++ ) visited[i] = false;
	
	
	for ( int i = 0; i < e; i++ ) {
		cin >> u >> v;
		G[u].push_back(v);
	
	}

	tsort();

	return 0;
}


Measured memory_bytes: 3984
/************************************/
/* NoobM							*/
/* File Name : abc.cpp				*/
/* Date : 25.07.2020 18:00:56 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	
	vi(n, a);
	
	int r = k;
	int l = 0;
	
	while(r < n) {
		if(a[r] > a[l]) cout << "Yes" << endl;
		else cout << "No" << endl;
		r++;
		l++;
	}
	
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3968
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
m2=[0]
for i in range(n):
  m.append(a[i])
for i in range(n):
  m2.append((m2[-1]+m[i]))
for i in range(n+1):
  m2[i]-=i
  m2[i]%=k

ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
  x=m2[i]
  if i<=k-1:
    dict[m2[i-1]]+=1
  else:
    dict[m2[i-1]]+=1
    dict[m2[i-k]]-=1
  ans+=dict[x]
print(ans)

Measured memory_bytes: 114060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] listStr = reader.readLine().split(" ");
    int w = Integer.parseInt(listStr[0]);
    int h = Integer.parseInt(listStr[1]);
    int x = Integer.parseInt(listStr[2]);
    int y = Integer.parseInt(listStr[3]);
    int r = Integer.parseInt(listStr[4]);

    if (x + r <= w && y + r <= h && x - r >= 0 && y - r >= 0)
      System.out.println("Yes");
    else
      System.out.println("No");

  }

}

Measured memory_bytes: 17088
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#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); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

#define int ll


class DSnukesColoring {
public:
    map<pii, int> mp;
    int A[11];
void solve(std::istream& cin, std::ostream& cout) {
    memset(A,0,sizeof(A));
    mp.clear();
    int H,W,N;
    cin >> H >> W >> N;
    _for(i,N){
        int a,b;
        cin >> a >> b;
        rep(dx,-1,2)rep(dy,-1,2)mp[{a+dx,b+dy}]++;
    }
    A[0] = (H-2)*(W-2);
    for(auto p : mp)if(intv(p.first.first,2,H-1) && intv(p.first.second,2,W-1))A[p.second]++,A[0] --;
    _for(i,10)cout << A[i] << endl;
}
};


#undef int
int main() {
	DSnukesColoring solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 56448
#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

struct kid {
  int index;
  long long int value;
};

bool operator < (struct kid a, struct kid b) {
  return a.value < b.value;
}

long long int ans;
long long int dp[2001][2001];

int main() {
  int N;
  priority_queue<struct kid> queue;
  struct kid A[2000];
  cin >> N;
  for (int i=0; i<N; i++) {
    A[i].index = i;
    cin >> A[i].value;
    queue.push(A[i]);
  }

  for (int i=0; i<=N; i++)
    for (int j=0; j<=N; j++)
      dp[i][j] = 0;

  int i=1;
  while (!queue.empty()) {
    struct kid kid = queue.top();

    for (int j=0; j<=i; j++) {
      long long int a=0, b=0;
      if (i-j > 0) {
        a = dp[j][i-j-1] + kid.value * max(kid.index - (N - (i-j)), (N - (i-j)) - kid.index);
      }
      if (j > 0) {
        b = dp[j-1][i-j] + kid.value * max(kid.index - (j - 1), (j - 1) - kid.index);
      }
      // printf("j:%d, N:%d, i:%d, index:%d, value:%d, a:%lld, b:%lld\n", j, N, i, kid.index, kid.value, a, b);

      dp[j][i-j] = max(a, b);
      ans = max (dp[j][i-j], ans);
    }

    i++;
    queue.pop();
  }

  // cout << endl;
  // for (int i=0; i<=N; i++) {
  //   for (int j=0; j<=N; j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 34956
n = int(input())
h = [int(elem) for elem in input().split()]

flg = 0
max = 0
if n > 1 :
  for i in range(n):
    if h[i] > max:
      max = h[i]
    elif h[i] < max-1 :
      flg = 1
      break
 
if flg == 1 :
  print('No')
else:
  print('Yes')

Measured memory_bytes: 14396
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
#define ll long long
#define mod 1000000007
using namespace std;
int n, s[N];
ll f[N];
int main(){
	scanf("%d", &n);
	f[1]=n; f[2]=(ll)n*n%mod;
	s[0]=0; for(int i=1; i<=2; i++)s[i]=(s[i-1]+f[i])%mod;
	for(int i=3; i<=n; i++){
		f[i]=(f[i-1]+s[i-3]+(ll)(n-1)*(i-3)%mod+(ll)n*(n-i+2)%mod)%mod;
		s[i]=(s[i-1]+f[i])%mod;
	}
	printf("%d", f[n]);
	return 0;
}

Measured memory_bytes: 11904
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H; int W;
	while (~scanf("%d%d", &H, &W)) {
		vector<string> S(H);
		for (int i = 0; i < H; ++ i) {
			cin >> S[i];
		}
		auto orgS = S;
		vector<string> revS;
		auto solve = [&]() {
			revS = S;
			for (auto &s : revS)
				reverse(s.begin(), s.end());
			int used = 0;
			int i = 0;
			for (int t = 0; t < H / 2; ++ t) {
				while (1) {
					for (; i < H && (used >> i & 1); ++ i);
					if (i == H) break;
					for (int k = i + 1; k < H; ++ k) if (~used >> k & 1) {
						if (S[i] == revS[k]) {
							used |= 1 << i;
							used |= 1 << k;
							goto ok;
						}
					}
					++ i;
				}
			ok:
				if (i == H) return false;
			}
			if (H % 2 == 1) {
				i = 0;
				for (; i < H && (used >> i & 1); ++ i);
				if (i == H) return false;
				return S[i] == revS[i];
			} else {
				return true;
			}
		};
		vector<bool> matched(W);
		auto swapCol = [&](int i, int j) {
			swap(matched[i], matched[j]);
			for (int k = 0; k < H; ++ k)
				swap(S[k][i], S[k][j]);
		};
		bool ans = false;
		function<void(int)> rec = [&](int i) {
			if (i == W / 2) {
				if (solve()) {
					ans = true;
				}
				return;
			}
			for (int j = 0; j < W; ++ j) if (i != j && !matched[j]) {
				matched[i] = matched[j] = true;
				swapCol(W - 1 - i, j);
				rec(i + 1);
				swapCol(W - 1 - i, j);
				matched[i] = matched[j] = false;
			}
		};
		if (W % 2 == 0) {
			rec(0);
		} else {
			for (int mid = 0; mid < W; ++ mid) {
				matched[mid] = true;
				swapCol(mid, W / 2);
				rec(0);
				swapCol(mid, W / 2);
				matched[mid] = false;
			}
		}
		puts(ans ? "YES" : "NO");
	}
}


Measured memory_bytes: 384
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

MOD = 10**9+7

dp = Array.new(N+1){Array.new(N+1){Array.new(256, 0)}}
dp[0][0][0] = 1
N.times do |i|
    (i+1).times do |j|
        256.times do |k|
            dp[i+1][j][k] += dp[i][j][k]
            dp[i+1][j][k] %= MOD
            dp[i+1][j+1][k^as[i]] += dp[i][j][k]
            dp[i+1][j+1][k^as[i]] %= MOD
        end
    end
end

fact = [1]
(1..N).each do |i|
    fact[i] = fact[i-1] * i % MOD
end

ans = 0
(1..N).each do |i|
    ans += dp[N][i][K] * fact[i] % MOD
    ans %= MOD
end
puts ans

Measured memory_bytes: 22652
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
 
   
int main(){
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  ll dif=abs(b-a);
  ll mv=(v-w)*t;
  if(mv>=dif)cout << "YES" << endl;
  else cout << "NO" << endl;
} 

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

int main() {
    int a, b;
    cin >> a >> b;
    int c = b;
    int count = 0;
    while (b) {
        count++;
        b /= 10;
    }
    for (int i = 0; i < count; i++) {
        a *= 10;
    }
    c += a;
    for (int i = 1; i * i <= c; i++) {
        if (c % i == 0 && c / i == i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            // C
            var line = System.Console.ReadLine();
            var N = System.Int32.Parse(line);
            var num = 0;
            var counter = 0;
            for (var i = 0; i < N; i++) {
                num = System.Int32.Parse(System.Console.ReadLine());

                if (num <= 3)
                {
                    counter++;
                    continue;
                }
                if (num % 2 == 0) continue;
                else
                {
                    if (CheckNum(num))
                    {
                        counter++;
                    }
                }
            }
            System.Console.WriteLine(counter);

        }

        static bool CheckNum(int num) {
            for (var i = 3; i <= Math.Sqrt(num); i+=2) { 
                if (num % i == 0) return false;
            }
            return true;
        }
}}

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


int main(){
  string S;
  cin >> S;

  
  int dis = 1000000;
  string str = S;
  for(int i = 0; i < S.size(); i++){
    str = S;
   string substr = str.substr(i,3);

   int num;
   num = stoi(substr);
   if(dis > abs(753 - num)){ dis = abs(753 - num); }

  }

  cout << dis << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc078/tasks/abc078_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  char x, y, r;
  string p = "ABCDEF";

  cin >> x >> y;

  r = x == y ? '=' : p.find(x) < p.find(y) ? '<' : '>';

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
program sample
    implicit none
    
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:) 

    read(*,*) n
  
    allocate(x(n))
    read(*,*) x
    call msort(x)
    a=x(n/2)
    b=x(n/2+1)
    write(*,*)b-a

    deallocate(x)
    stop

    contains

    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 2740
import java.util.Scanner;

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

		int[] ant = new int[5];
		int dis = 0;

		for(int i = 0; i < 5; i++) {
			ant[i] = sc.nextInt();
		}
		dis = sc.nextInt();

		for(int i = 0; i < 4; i++) {
			for(int j = i + 1; j < 5; j++) {
				if(ant[j] - ant[i] > dis) {
					System.out.println(":(");
					System.exit(0);
				}
			}
		}
		System.out.println("Yay!");
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

char c;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> c;
	cout << (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? "vowel" : "consonant") << endl;
	return 0;
}

Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;


#define int long long
// #define double ld
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
const int N = 1e4 + 5;
int dp[N];
signed main() {
    srand(time(0));
    accell();
    int h, n;
    cin >> h >> n;
    fill(dp, dp + h + 1, 1e18);
    dp[0] = 0;
    for (int j = 0; j < n; ++j) {
        int a, b;
        cin >> a >> b;
        for (int i = 0; i < h; ++i) {
            dp[min(i + a, h)] = min(dp[min(i + a, h)], dp[i] + b);
        }
    }
    cout << dp[h];
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

double getRate(double a, double b){
	return abs(a - b) / a;
}

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

	vector<int> a(n);
	cin >> a;

	vector<vector<double>> dp(n, vector<double>(200000, numeric_limits<double>::max()));
	rep(i,n){
		range(j,1,200000){
			if(i == 0){
				dp[i][j] = getRate(a[i], j);
			}else{
				for(int k = j; k < 200000; k+=j){
					dp[i][k] = min(dp[i][k], max(dp[i - 1][j], getRate(a[i], k)));
				}
			}
		}
	}

	cout << fixed << setprecision(10) << *min_element(all(dp[n - 1])) << endl;
}



Measured memory_bytes: 35500
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>

using namespace std;
 
int main() {
    char a[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    char t;
    cin >> t;
    for(int i = 0; i < 26; i++) {
        if(t == a[i]) {
            cout << a[i+1] << endl;
            return 0;
        }
    }

	return 0;		
    
}

Measured memory_bytes: 256
import numpy as np
h, w, m = map(int, input().split())
xy = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]
row = np.zeros(h, np.int)
col = np.zeros(w, np.int)
for y, x in xy:
	row[y] += 1
	col[x] += 1

max_cnt_y = max(row)
max_cnt_x = max(col)
max_pair = np.sum(row == max_cnt_y) * np.sum(col == max_cnt_x)
for y, x in xy:
	if row[y] == max_cnt_y and col[x] == max_cnt_x:
		max_pair -= 1

print(max_cnt_y + max_cnt_x - (max_pair == 0))

Measured memory_bytes: 72372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using vi = vector<int>;

const int N = 50;
const int INF = 19191919;

int r,c,m;
string s[N];
int comp[N][N], on[N][N], off[N][N];
pi task[1000];

vi t[N][N];

vector<pi> route(pi start, pi goal)
{
    int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
    #define IN(y,x) (0<=y && y<r && 0<=x && x<c)

    vector<vi> d(r,vi(c,INF));
    vector<vector<pi>> par(r,vector<pi>(c));
    queue<pi> que;

    d[start.fi][start.se]=0;
    que.push(start);

    while(!que.empty())
    {
        pi now = que.front();
        que.pop();
        rep(i,4)
        {
            int nx=now.se+dx[i], ny=now.fi+dy[i];
            if(IN(ny,nx) && s[ny][nx]=='.' && d[ny][nx]>d[now.fi][now.se]+1)
            {
                d[ny][nx] = d[now.fi][now.se]+1;
                par[ny][nx] = now;
                que.push({ny,nx});
            }
        }
    }

    vector<pi> ret;
    pi now=goal;
    while(now != start)
    {
        ret.pb(now);
        now = par[now.fi][now.se];
    }
    reverse(all(ret));
    return ret;
}

int main()
{
    cin >>r >>c >>m;
    rep(i,r) cin >>s[i];
    rep(i,r)rep(j,c) cin >>comp[i][j];
    rep(i,r)rep(j,c) cin >>on[i][j];
    rep(i,r)rep(j,c) cin >>off[i][j];
    rep(i,m) cin >>task[i].fi >>task[i].se;

    vector<pi> vis;
    vis.pb(task[0]);
    rep(i,m-1)for(const auto &p:route(task[i],task[i+1])) vis.pb(p);

    rep(i,vis.size())
    {
        int y=vis[i].fi, x=vis[i].se;
        t[y][x].pb(i);
    }

    ll ans = 0;
    rep(i,r)rep(j,c)if(t[i][j].size()>0)
    {
        ll add = on[i][j]+off[i][j];

        vi stamp = t[i][j];
        int S = stamp.size();
        rep(k,S-1) add += min(on[i][j]+off[i][j], comp[i][j]*(stamp[k+1]-stamp[k]));

        ans += add;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19544
# -*- coding: utf-8 -*-

import sys
from itertools import permutations

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
P = tuple(LIST())
Q = tuple(LIST())

a = b = 0
for i, perm in enumerate(sorted(permutations(range(1, N+1)))):
    if perm == P:
        a = i + 1
    if perm == Q:
        b = i + 1
print(abs(a - b))


Measured memory_bytes: 8052
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back


#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64_t
#endif


const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

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


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


 main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int a = readInt(), b = readInt(), useless = readInt(), d = readInt(), e = readInt();
    int ans = (a / 2) * 2 + (d / 2) * 2 + (e / 2) * 2;
    if (a >= 1 && d >= 1 && e >= 1) {
		ans = max(ans, 3 + ((a - 1) / 2) * 2 + ((d - 1) / 2) * 2 + ((e - 1) / 2) * 2);    
    }
    cout << ans + b;
    return 0;
}
//│──────│
//└── ───┘


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a;
	int b;
	char op;
	int p;
	int m;
	int w;
	int k;
	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+'){
		p=a+b;
		printf("%d\n",p);
	}else if(op=='-'){
		m=a-b;
		printf("%d\n",m);
	}else if(op=='*'){
		k=a*b;
		printf("%d\n",k);
	}else if(op=='/'){
		w=a/b;
		printf("%d\n",w);
	}else if(op=='?'){
		break;
	}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

int lcm(int a, int b)
{
    return a / std::__gcd(a, b) * b;
}

int main()
{
    int N, M;
    std::cin >> N >> M;
    
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    
    long long res = 0;
    int max = INT_MIN, min = INT_MAX;
    for (int i = 0, j = 0; i < lcm(N, M); i++, j++) {
        max = std::max(max, A[i % N]);
        min = std::min(min, A[i % N]);
        
        if (j + 1 == M) {
            res += max - min;
            j = -1;
            max = INT_MIN;
            min = INT_MAX;
        }
    }
    std::cout << res << std::endl;    
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    string s, t; cin >> s >> t;
    reverse(ALL(s));
    reverse(ALL(t));
    string ans="";
    if(s.size()<t.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i = 0; i <= s.size()-t.size(); i++){
        bool flag = true;
        int now = i;
        for(int j = 0; j < t.size(); j++){
            if(s[now]!='?'){
                if(s[now]!=t[j]) {
                    flag = false;
                    break;
                }
            }
            now++;

        }
        if(flag) {
            for(int k = 0; k < s.size();){
                if(k==i){
                    ans+=t;
                    k+=t.size();
                }else {
                    if(s[k]=='?'){
                        ans+='a';
                        k++;
                    }else{
                        ans+=s[k];
                        k++;
                    }
                }
            }
            reverse(ALL(ans));
            cout << ans << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;

    return 0;
}

Measured memory_bytes: 256
//Finite Disappointment and Infinite Hope
#include <bits/stdc++.h>
using namespace std;
#define help ios_base:: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(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) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.first<<","<<v.second<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    for(auto &x:c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
const ll N=2e5+5,MOD=1e9+7;
ll func(ll n){
    if(n<1)return 0;
    return 1 + 2*func(n/2);
}
int main(){
help
    ll h;cin>>h;
    cout<<func(h);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int k;
    cin >> k;
    if (k % 2 == 0 || k % 5 == 0) cout << -1 << '\n';
    else if (k == 1 || k == 7) cout << 1 << '\n';
    else {
        int cnt = 1, rem = 7;
        while (rem != 0) {
            rem = (rem * 10 + 7) % k;
            cnt++;
        }
        cout << cnt << '\n';
    }
}

Measured memory_bytes: 3564