akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	static int N;
	static int Ma;
	static int Mb;
	static int[]a;
	static int[]b;
	static int[]c;
    static int ca;
	static int cb;
	static final int INF=10000;
	static int ans;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		N=sc.nextInt();
		Ma=sc.nextInt();
		Mb=sc.nextInt();
		a=new int[N];
		b=new int[N];
		c=new int[N];
		for(int i=0;i<N;i++){
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		int[][][]dp=new int[N+1][400][400];
		
		for(int i=0;i<N+1;i++){
			for(int j=0;j<400;j++){
				for(int k=0;k<400;k++){
					dp[i][j][k]=INF;
				}
			}
		}
		dp[0][0][0]=0;
		
		for(int i=0;i<N;i++){
			for(ca=0;ca<400;ca++){
				for(cb=0;cb<400;cb++){
					if(dp[i][ca][cb]!=INF){
						dp[i+1][ca][cb]=Math.min(dp[i+1][ca][cb], dp[i][ca][cb]);
						dp[i+1][ca+a[i]][cb+b[i]]=Math.min(dp[i+1][ca+a[i]][cb+b[i]],(dp[i][ca][cb]+c[i]));
					}
				}
			}
		}
		
		ans=INF;
		for(ca=1;ca<400;ca++){
			for(cb=1;cb<400;cb++){
				if(ca*Mb==Ma*cb)ans=Math.min(ans, dp[N][ca][cb]);
			}
		}
		
		if(ans!=INF)System.out.println(ans);
		else System.out.println(-1);
	}
	
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, a, b, c, d;
unordered_map<li, li> memo;

inline li dfs(li x) {
    if (x == 0) {
        return memo[x] = 0;
    }
    if (x == 1) {
        return memo[x] = d;
    }
    if (memo.count(x) > 0) {
        return memo[x];
    }
    //cout << x << endl;
    li res = bit(62);
    if (res / d > x) {
        res = min(res, d * x);
    }
    res = min(res, a + (x % 2) * d + dfs(x / 2));
    if (x % 2 > 0)res = min(res, a + (2 - x % 2) * d + dfs(x / 2 + 1));
    res = min(res, b + (x % 3) * d + dfs(x / 3));
    if (x % 3 > 0)res = min(res, b + (3 - x % 3) * d + dfs(x / 3 + 1));
    res = min(res, c + (x % 5) * d + dfs(x / 5));
    if (x % 5 > 0)res = min(res, c + (5 - x % 5) * d + dfs(x / 5 + 1));
    return memo[x] = res;
}

inline void solve() {
    memo.clear();
    cin >> n >> a >> b >> c >> d;

    cout << dfs(n) << endl;
}

int main() {
    li t;
    cin >> t;
    rep(i, t) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 4144
#include <stdio.h>
#define ok printf("ok\n");

long long max(long long a, long long b){
    if(a>b)
        return a;
    else
        return b;
}

int w[110];
int v[110];
long long x[110000];

int main(){
    int n, wmax;

    scanf("%d%d", &n, &wmax);

    for(int i=0; i<n; i++){
        scanf("%d%d", w+i, v+i);
    }

    for(int i=0; i<n; i++){
        for(int j=wmax; j>=0; j--){
            if(j+w[i]<=wmax){
                x[j+w[i]]=max(x[j+w[i]], x[j]+v[i]);
            }
        }
    }

    long long ret = 0;

    for(int i=0; i<=wmax; i++){
        ret = max(x[i], ret);
    }

    printf("%lld", ret);
}


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

using namespace std;

int h, w, sy, sx, gy, gx;
char m[1000][1000];
bool visited[1000][1000];
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, -1, 0, 1};
int ans = -1;
vector<pair<int, int>> vst, next_vst;

void go(int y, int x, int cnt){
    visited[y][x] = true;
    // cout << "y is : " << y << " x is : " << x << '\n';
    next_vst.push_back({y, x});
    if(y == gy && x == gx){
        ans = cnt;
        return;
    }
    for(int i=0; i<4; i++){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(0 <= ny && ny < h && 0 <= nx && nx < w && !visited[ny][nx]
        && m[ny][nx] == '.'){
            go(ny, nx, cnt);
        }
    }    
    // for(int ny = y-2; ny < y+2; ny++){
    //     for(int nx = x-2; nx < x+2; nx++){
    //         if(0 <= ny && ny < h && 0 <= nx && nx < w && !visited[ny][nx]
    //     && m[ny][nx] == '.'){
    //             go(ny, nx, cnt+1);
    //         }
    //     }
    // }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> h >> w;
    cin >> sy >> sx;
    cin >> gy >> gx;
    sy--; sx--; gy--; gx--;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> m[i][j];
            //cout << m[i][j] << ' ';
        }
        //cout << '\n';
    }
    int cnt = 0;
    vst.push_back({sy, sx});
    while(!vst.empty()){
        for(int i=0; i<vst.size(); i++){
            pair<int, int> p = vst[i];
            sy = p.first;
            sx = p.second;
            if(!visited[sy][sx])
                go(sy, sx, cnt);
        }
        //vst = next_vst;
        //next_vst.clear();
        vst.clear();
        for(int i=0; i<next_vst.size(); i++){
            pair<int, int> p = next_vst[i];
            int y = p.first;
            int x = p.second;
            for(int ny = y-2; ny <= y+2; ny++){
                for(int nx = x-2; nx <= x+2; nx++){
                    if(0 <= ny && ny < h && 0 <= nx && nx < w && !visited[ny][nx]
                    && m[ny][nx] == '.'){
                        vst.push_back({ny, nx});
                    }
                }
            }       
        }
        next_vst.clear();
        cnt++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5584
//2017/09/16
//????????????
//??????????????????C++

#include <iostream>
using namespace std;
int main() {
	int num1, num2;

	cin >> num1 >> num2;

	cout << num1*num2 << ' ' << num1 * 2 + num2 * 2 << "\n";

	return 0;
}

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
from collections import Counter

def solve(N: int, L: "List[int]"):
    L=sorted(L)
    ans=0
    if N<3:
        print(0)
        exit()
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                a,b,c=L[i],L[j],L[k]
                if a==b or a==c or b==c:
                    continue
                if a < b + c and b < a + c and c < a + b:
                    ans+=1

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9464
#include <stdio.h>

int main(void){
    int H[5]={},x;
    for (int i=0; i<10; i++) {
        scanf("%d",&x);
        for (int i=0; i<3; i++) {
            if (x>H[i]) {
                H[i+2]=H[i+1];
                H[i+1]=H[i];
                H[i]=x;
                break;
            }
        }
    }
    for (int i=0; i<3; i++) {
        printf("%d\n",H[i]);
    }
    return 0;
}


Measured memory_bytes: 2056
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String S = sc.next();
		
		int ans =0;
		for (int i = 1; i < S.length(); i++) {
			String s = S.substring(0, S.length() - i);
			if (s.length() % 2 == 1) continue;
			int half = s.length() / 2;
	
			if (s.substring(0, half).equals(s.substring(half, half + half))) {
				ans = s.length();
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include<stdio.h>
int main(void){
	int len1,len2,len;
	int counttyo = 0;
	int counthisi = 0;
	while(scanf("%d,%d,%d",&len1,&len2,&len) != EOF){
		if(len * len == len1 * len1 + len2 * len2){
			counttyo++;
		}
		if(len1 == len2){
			counthisi++;
		}
	}
	printf("%d\n%d\n",counttyo,counthisi);
	return 0;
}

Measured memory_bytes: 596
import collections

def solve(height, road):
    graph = collections.defaultdict(set)
    for a, b in road:
        graph[a].add(b)
        graph[b].add(a)
    ans = 0
    no_good = set()
    for k in graph:
        for nei in graph[k]:
            if height[nei-1] >= height[k-1]:
                no_good.add(k)
    return len(height) -  len(no_good)

obs, k = map(int, input().split())
height = list(map(int, input().split()))
road = []
for _ in range(k):
    r = list(map(int, input().split()))
    road.append(r)
print(solve(height, road))


Measured memory_bytes: 59496
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int main() {
	int N, K, t;
	double p = 0;
	scanf("%d%d", &N, &K);
	rep(i, 1, N + 1) {
		t = 1;
		while (K > i * t)t *= 2;
		p += 1 / (double)t;
	}
	printf("%.10f\n", p / N);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
vi s[2];
bitset < (1 << 16) > D;
int main(void)
{
    string str;
    cin>>str;
    int xx,yy;
    cin>>xx>>yy;
    int a = 0,b = 0;
    int was = 0;
    for (auto it : str)
    {
        if (it == 'T')
        {
            if (!was)
                xx -= a;
            else
                s[b].pb(a);
            was = 1;
            a = 0;
            b ^= 1;
        }
        else ++a;
    }
    if (!was)
        xx -= a;
    else
        s[b].pb(a);
    vi v = {xx,yy};
    for (int cs = 0;cs < 2;++cs)
    {
        D.reset();
        D[0] = 1;
        for (auto it : s[cs])
            D |= D << (it + it);
        int sum = accumulate(all(s[cs]),0);
        int cnt = sum + v[cs];
        if (!(0 <= cnt && cnt <= 2 * sum))
            return puts("No") * 0;
        if (!D[cnt])
            return 0 * puts("No");
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int H,W,K;
vector<string> S;

int cut (vector<vector<string>> choco)
{
    int ret = choco.size() - 1;
    int pre = 0;
    vector<int> cnt(choco.size(), 0);
    for (int i = 0; i < W; i++) {
        for (int j = 0; j < choco.size(); j++) {
            for (int k = 0; k < choco[j].size(); k++) {
                if (choco[j][k][i] == '1') {
                    cnt[j]++;
                }
            }
        }
        bool flag_over = false;
        for (int j = 0; j < cnt.size(); j++) {
            if (cnt[j] > K ) flag_over = true;
        }
        if (flag_over) {
            if (i == pre) {
                return 1e9;
            }
            pre = i;
            i--;
            ret++;
            for (int j = 0; j < cnt.size(); j++) {
                cnt[j] = 0;
            }
        }
    }
    return ret;
}

vector<vector<string>> get_choco (int n)
{
    vector<vector<string>> ret;
    vector<int> pos;
    for (int i = 0; i < (H - 1); i++) {
        if ((n >> i) & 1) {
            pos.push_back(i + 1);
        }
    }

    pos.push_back(H);
    int cur = 0;
    for (auto i: pos) {
        vector<string> t;
        for (; cur < i; cur++) {
            t.push_back(S[cur]);
        }
        ret.push_back(t);
    }
    return ret;
}

int main ()
{
    cin >> H >> W >> K;
    S.resize(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    int best_ans = 1e9;
    for (int i = 0; i < (1 << (H - 1)); i++) {
        vector<vector<string>> choco = get_choco(i);
        best_ans = min(best_ans, cut(choco));
    }

    assert(best_ans < 1e9);

    cout << best_ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int[][] matrix = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int a = sc.nextInt();
				matrix[i][j] = a;
			}
		}

		int[] vector = new int[m];
		for (int i = 0; i < m; i++) {
			vector[i] = sc.nextInt();
		}

		sc.close();

		int[] calcdVector = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				calcdVector[i] += matrix[i][j] * vector[j];
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.println(calcdVector[i]);
		}
	}
}

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

int main(){
    string s,t;
    cin >>s>>t;
    for(int i=0;i<t.size()-1;i++){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.io.*;
class Work implements Comparable<Work>{
	public Work(long a, long b) {
		this.a = a;
		this.b = b;
	}
	long a;
	long b;
	@Override
	public int compareTo(Work o) {
		if(this.b < o.b)return -1;
		if(this.b > o.b)return 1;
		return 0;
	}	
}
public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		Work[] wa = new Work[n];
		for(int i = 0; i < n; i++) {
			wa[i] = new Work(nl(),nl());
		}
		Arrays.sort(wa);
		//Arrays.stream(wa).forEach(v -> System.out.println("a:" + v.a + " b:" + v.b));
		long asum = 0L;
		for(int i = 0; i < n; i++) {
			asum += wa[i].a;
			if(asum > wa[i].b) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] > a[j]) {
                ans += k;
                ans %= MOD;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        ll cnt = 0;
        for (int j = 0; j < n; ++j) {
            if (a[i] > a[j]) {
                cnt++;
            }
        }
        ans += (((k * (k - 1)) / 2) % MOD) * cnt;
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
# coding: utf-8
import heapq
n=int(input())
cost=[]
used=[False for i in range(n)]
for i in range(n):
    cost.append(list(map(int,input().split())))
q=[]
heapq.heappush(q,(0,0))
ans=0
while len(q):
    c,newv=heapq.heappop(q)
    if used[newv]:
        continue
    used[newv]=True
    ans+=c
    for nxt in range(n):
        if cost[newv][nxt]!=-1 and not used[nxt]:
            heapq.heappush(q,(cost[newv][nxt],nxt))
print(ans)

    


Measured memory_bytes: 6088
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt(), b = s.nextInt(), c = s.nextInt();
		if (a == b && a == c) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

void solve(){
    while(1){
        ll w,h;cin>>w>>h;
        if(w==0&&h==0)break;
        vvl b1(h,vl(w-1)),b2(h-1,vl(w));
        rep(i,h-1){
            rep(j,w-1)cin>>b1[i][j];
            rep(j,w)cin>>b2[i][j];
        }
        rep(j,w-1)cin>>b1[h-1][j];

        vvl d(h,vl(w));
        d[0][0]=1;
        queue<pl> q;
        q.push(pl(0,0));
        while(!q.empty()){
            pl p=q.front();q.pop();
            ll y=p.first,x=p.second;
            if(y>0&&!b2[y-1][x]&&!d[y-1][x]){
                d[y-1][x]=d[y][x]+1;
                q.push(pl(y-1,x));
            }
            if(y<h-1&&!b2[y][x]&&!d[y+1][x]){
                d[y+1][x]=d[y][x]+1;
                q.push(pl(y+1,x));
            }
            if(x>0&&!b1[y][x-1]&&!d[y][x-1]){
                d[y][x-1]=d[y][x]+1;
                q.push(pl(y,x-1));
            }
            if(x<w-1&&!b1[y][x]&&!d[y][x+1]){
                d[y][x+1]=d[y][x]+1;
                q.push(pl(y,x+1));
            }
        }
        cout<<d[h-1][w-1]<<endl;
    }
}

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



Measured memory_bytes: 3136
#include "bits/stdc++.h"
using namespace std;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (s-(i + j) >= 0 && s-(i+j) <= k) {
				ans++;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = gets.chomp.split(' ').map(&:to_i)
x_dist = x1 - x2
y_dist = y1 - y2

x3 = x2 + y_dist
y3 = y2 - x_dist

x4 = x1 + y_dist
y4 = y1 - x_dist
print [x3, y3, x4, y4].join(' ')

Measured memory_bytes: 1788
# C - 怪文書 / Dubious Document

n = int(input())
S = [input() for _ in range(n)]

alf = [[] for _ in range(26)]

for string in S:
    tmp = [0]*26
    for letter in string:
        tmp[ord(letter) - 97] += 1
    for al in range(26):
        alf[al].append(tmp[al])

alf = [min(x) for x in alf]
ans = ""
for al in range(26):
    ans += chr(al+97) * alf[al]
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    char buf[20];
    char  *priceA, *priceB, *priceC;
    int   pA,pB,pC,min;
    fgets(buf,sizeof(buf)+1,stdin);
    priceA = strtok(buf ," ");
    priceB = strtok(NULL," ");
    priceC = strtok(NULL," ");
    
    pA = atoi(priceA);
    pB = atoi(priceB);
    pC = atoi(priceC);

    min = pA+pB;
    if(pA+pC <= min) min = pA+pC;
    if(pB+pC <= min) min = pB+pC;

    printf("%d",min);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  ll o = 0;
  for(int i = 1; i <= n; i++)
    if(i % 3 && i % 5) o += i;
  printf("%lld\n", o);
}

Measured memory_bytes: 3828
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;

int main()
{
	int N, M, i,D,X, j, k, l, m, n, sum, cnt, flag;
	cin >> N;
	vector<int>A(N+2);
	A[0] = 0;
	A[N + 1] = 0;
	for (i = 1; i <= N; i++) {
		cin >> A[i];
	}
	sum = 0;
	flag = 0;
	cnt = 0;
	for (i = 0; i <= N; i++) {
		sum += abs(A[i+1]-A[i]);
	}
	for (i = 1; i <= N; i++) {
		cout << sum - abs(A[i - 1] - A[i])-abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]) << endl;
	}
	return 0;
}



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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  z = (Node*)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x!=NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y==NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void preorder(Node *v) {
  if (v==NIL) {
    return;
  }
  cout << " " << v->key;
  preorder(v->left);
  preorder(v->right);
}

void inorder(Node *v) {
  if (v==NIL) {
    return;
  }
  inorder(v->left);
  cout << " " << v->key;
  inorder(v->right);
}

int main() {
  int n;
  cin >> n;
  int x;
  string com;
  for (int i=0; i<n; i++) {
    cin >> com;
    if (com=="insert") {
      cin >> x;
      insert(x);
    } else if (com=="print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;

    }
  }
  return 0;
}



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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") { 
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  LL h;
  LL c = 1, cc = 0;
  cin >> h;
  while (h) {
    c *= 2;
    cc += c;
    h /= 2;
  }
  cout << c - 1 << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3560
/*
 * Author: ylx
 * Lang: c++
 * Prog: duliu
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
__gnu_pbds::gp_hash_table<int,int> Map;
const int maxn=2e5+100;
int a[maxn],b[maxn],n,c[maxn],d[maxn];
int fa[maxn];
int gf(int x)
{
	if (fa[x]==x) return x;
	return fa[x]=gf(fa[x]);
}
int main()
{
#ifdef ylx
	freopen("duliu.in","r",stdin);
	freopen("duliu.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) a[i]=read(),c[i]=a[i],c[n+1]^=a[i];
	a[n+1]=c[n+1];
	for (int i=1;i<=n;i++) b[i]=read(),d[i]=b[i],d[n+1]^=b[i];
	b[n+1]=d[n+1];
	sort(c+1,c+n+2);
	sort(d+1,d+n+2);
	for (int i=1;i<=n+1;i++)
	if (c[i]^d[i])
	{
		putchar('-');
		putchar('1');
		return 0;
	}
	int cnt=0,ans=0;
	for (int i=1;i<=n+1;i++)
	if (a[i]^b[i]||i==n+1)
	{
		ans+=i<=n;
		if (!Map[a[i]]) Map[a[i]]=++cnt;
		if (!Map[b[i]]) Map[b[i]]=++cnt;
	}
	for (int i=1;i<=cnt;i++) fa[i]=i;
	for (int i=1;i<=n+1;i++)
	if (a[i]^b[i])
	{
		fa[gf(Map[a[i]])]=gf(Map[b[i]]);
	}
	for (int i=1;i<=cnt;i++)  if (fa[i]==i) ans++;
	ans--;
	cout<<ans;
	return 0;
}
//2018年 10月 19日 星期五 16:15:18 CST


Measured memory_bytes: 8432
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  map<string, ll> par;
  for (ll i = 1; i <= n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    par[s]++;
  }

  ll res = 0;
  for (auto it : par)
    res += it.second * (it.second - 1) / 2;

  cout << res << en;

  return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
typedef long long ll;
const int MOD = 1e9 + 7;
using namespace std;

ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll cmb(ll n, ll a) {
	if (n - a < a) return cmb(n, n - a);

	ll res = 1;
	for (ll i = n; n - a + 1 <= i; i--) { res *= i;  res %= MOD; }
	for (ll i = 2; i <= a; i++) { res = res * modinv(i, MOD) % MOD; }

	return res;
}

int main() {
	ll n, a, b;
  	cin >> n >> a >> b;
	ll ans = modpow(2, n) - 1 - cmb(n, a) - cmb(n, b);
	while (ans < 0)
      ans += MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
struct road {
	int to;
	int cost;
	int attack;
};
struct aa {
	int now;
	int money;
	int damage;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.damage> r.damage;
	}
};
int N, M, L;
int memo[100][10001];
int check(const vector<vector<road>>&edges, int amoney) {
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 10001; ++j) {
			memo[i][j] = 999999999;
		}
	}
	memo[0][amoney] = 0;
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ 0,amoney,0 });
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.now == N - 1)return atop.damage;
		else {
			for (auto e : edges[atop.now]) {
				{
					if (atop.money >= e.cost) {
						if (memo[e.to][atop.money - e.cost]>atop.damage) {
							memo[e.to][atop.money - e.cost] = atop.damage;
							que.push({ e.to,atop.money - e.cost,atop.damage });
						}
					}
					{
						if (memo[e.to][atop.money]>atop.damage+e.attack) {
							memo[e.to][atop.money] = atop.damage + e.attack;
							que.push({ e.to,atop.money,atop.damage + e.attack });
						}
					}
				}
			}
		}
	}
}

int main() {
	while (1) {
		cin >> N >> M >> L;
		if (!N)break;
		vector<vector<road>>roads(N);
		for (int i = 0; i < M; ++i) {
			int a, b, d, e; cin >> a >> b >> d >> e;
			a--; b--;
			roads[a].push_back(road{ b,d,e });
			roads[b].push_back(road{ a,d,e });
		}
		long long amin = -1;
		long long amax = 99999999;
		int ans = check(roads, L);
		cout << ans << endl;
		/*while (amin + 1 != amax) {
			long long amid = (amin + amax) / 2;
			if (check(roads,amid)) {
				amax = amid;
			}
			else {
				amin = amid;
			}
		}
		cout << amax << endl;*/
	}
	
	return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (n) ; ++i)
#define mod 1000000007

using namespace std;
using ll=long long;
const ll INF = 100000000;

vector<int> to[200000];

int main() {
    ll n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : to[v]) {
            if (dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0)continue;
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 13028
def handstand(N: int, K: int, S: str)->int:
    seq = [[], []]
    cur_c, cur_n = S[0], 0

    if S[0] == '0':
        seq[1].append(0)

    for c in S:
        if cur_c != c:
            seq[int(cur_c)].append(cur_n)
            cur_c = c
            cur_n = 0
        cur_n += 1
    else:
        seq[int(cur_c)].append(cur_n)

    if S[-1] == '0':
        seq[1].append(0)

    if len(seq[0]) <= K:
        # 0 の領域が K こ以内なら全てひっくり返せる。
        return N

    cum = [sum(seq[0][:K]), sum(seq[1][:K+1])]
    max_up = sum(cum)

    for k in range(len(seq[0])-K):
        cum[0] += seq[0][k+K] - seq[0][k]
        cum[1] += seq[1][k+K+1] - seq[1][k]

        max_up = max(max_up, sum(cum))

    return max_up


if __name__ == "__main__":
    N, K = map(int, input().split())
    S = input()
    ans = handstand(N, K, S)
    print(ans)


Measured memory_bytes: 4408
a,b = map(int,input().split())
ans = 0
if a % 3 == 0:
  ans += 1
elif b % 3 == 0:
  ans +=1
elif (a + b) % 3 == 0:
  ans += 1

if ans > 0:
  print('Possible')
else:
  print('Impossible')

Measured memory_bytes: 2940
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (const T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int s, w;
	cin >> s >> w;
	cout << (w >= s ? "unsafe" : "safe");
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define repr(i,a,n) for (int i=a;i<n;i++)
#define rrep(i,a,n) for (int i=n-1;i>=a;i--)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define fi first
#define se second
#define mod 1000000007
const int N = 2e5 + 5;
#define PI acos(-1.0)
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(ll a, ll b) { if (a < b)swap(a, b); return (((a%mod) - (b%mod) + mod) % mod); }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {

	return;
}

signed main()
{
	fastio;
	int x, a;
	cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	}
	else
	{
		cout << 10 << endl;
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int i,n,m,temp=0;
int a[200010],b[200010],c[200010],d[200010];
int main(void)
{
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;i++)
	scanf("%d %d",&a[i],&b[i]);
	for(i=1;i<=m;i++)
	{
		if(a[i]==1)
		c[b[i]]++;
		if(b[i]==n)
		d[a[i]]++;
	}
	for(i=1;i<=m;i++)
	{
		if(c[i]>0&&d[i]>0)
		temp=1;
	}
	if(temp==1)
	printf("POSSIBLE\n");
	else
	printf("IMPOSSIBLE\n");
 } 

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

const int mod = 1e9 + 7;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}

int N, M;
int A[20], fact[1 << 17], invf[1 << 17];
int comb(int n, int k) {
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}

int cc[20][1 << 16];
int dp(int m, int mask) {
    if(m == -1) {
        int cnt = 0;
        for(int i = 0; i < N; i++) {
            if(mask & (1 << i)) cnt++;
        }
        if(cnt % 2) return (mod - fact[ (1 << N) - 1 - mask ]) % mod;
        else return fact[ (1 << N) - 1 - mask ];
    }
    int &ret = cc[m][mask];
    if(ret != -1) return ret;

    ret = dp(m - 1, mask);
    for(int i = 0; i < N; i++) {
        if(mask & (1 << i)) continue;
        if((1 << N) - A[m] - mask < (1 << i) - 1) break;

        ret += 1LL * comb((1 << N) - A[m] - mask, (1 << i) - 1) * fact[ (1 << i) ] % mod * dp(m - 1, mask ^ (1 << i)) % mod;
        ret %= mod;
    }
    return ret;
}

int main() {
    fact[0] = 1;
    for(int i = 1; i < (1 << 17); i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < (1 << 17); i++) {
        invf[i] = inv(fact[i]);
    }
    scanf("%d %d", &N, &M);

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

    memset(cc, -1, sizeof(cc));
    int ans = 1LL * (1 << N) * dp(M - 1, 0) % mod;
    printf("%d", ans);
}


Measured memory_bytes: 6400
def main():
    N = int(input())
    P = [float(x) for x in input().split()]
    over = (N + 1) // 2
    dp = [[0.0] * (over + 1) for _ in range(N + 1)]
    dp[0][0] = 1.0
    for i in range(N):
        for j in range(over):
            dp[i+1][j] += dp[i][j] * (1 - P[i])
            dp[i+1][j+1] += dp[i][j] * P[i]
        dp[i+1][over] += dp[i][over]
    print("{:.20f}".format(dp[-1][-1]))


if __name__ == '__main__':
    main()


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

using namespace std;

void solve()
{
	string A, B, C;
	cin >> A >> B >> C;
	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){
	int H, W;
	
	for(;;){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {

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

        int x = sc.nextInt();
        int n = sc.nextInt();

        int array[] = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int tmp = x;

        boolean flg = false;


        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < n; j++) {
                if (array[j] == x - i){
                    flg = true;
                }
            }

            if (flg == false) {
                System.out.println(x - i);
                return;
            }

            flg = false;

            for (int j = 0; j < n; j++) {
                if (array[j] == x + i){
                    flg = true;
                }
            }

            if (flg == false) {
                System.out.println(x + i);
                return;
            }

            flg = false;


        }







        sc.close();
    }

}

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

template <typename T>
struct BIT
{
    int n;
    vector<T> bit;
    
    BIT(){}
    
    BIT(int n) : n(n){
        bit.resize(n + 1);
    }
    
    T sum(int i){
        i++;
        T res = 0;
        while(i){
            res += bit[i];
            i -= (i & -i);
        }
        return res;
    }
    
    void add(int i, T x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += (i & -i);
        }
    }
};

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<BIT<int>> bit(26, BIT<int>(n));
    for(int i = 0; i < n; i++){
        bit[s[i] - 'a'].add(i, 1);
    }
    int q;
    cin >> q;
    while(q--){
        int p;
        cin >> p;
        if(p == 1){
            int i;
            char c;
            cin >> i >> c;
            i--;
            bit[s[i] - 'a'].add(i, -1);
            s[i] = c;
            bit[s[i] - 'a'].add(i, 1);
        }
        else{
            int l, r;
            cin >> l >> r;
            r--; l -= 2;
            int ans = 0;
            for(int i = 0; i < 26; i++) ans += min(1, bit[i].sum(r) - bit[i].sum(l));
            cout << ans << endl;
        }
    }
}

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

using namespace std;
using ll = long long;

int main() {
    string a;
    cin >> a;
    if(a[2] == a[3] && a[4] == a[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// 2011/07/31 Tazoe

#include <iostream>
using namespace std;

struct team{
	char nam;
	int  win;
	int  los;
	int  drw;
	int  sn;
};

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		struct team T[10];
		for(int i=0; i<n; i++){
			cin >> T[i].nam;

			T[i].win = T[i].los = T[i].drw = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;
				if(r==0)
					T[i].win++;
				else if(r==1)
					T[i].los++;
				else if(r==2)
					T[i].drw++;
			}

			T[i].sn = i;
		}

		for(int i=0; i<n-1; i++)
			for(int j=i+1; j<n; j++)
				if(T[i].win<T[j].win
				 ||(T[i].win==T[j].win&&T[i].los>T[j].los)
				 ||(T[i].win==T[j].win&&T[i].los==T[j].los&&T[i].sn>T[j].sn)){
					struct team tmp = T[i];
					T[i] = T[j];
					T[j] = tmp;
				}

		for(int i=0; i<n; i++)
			cout << T[i].nam << endl;
	}

	return 0;
}

Measured memory_bytes: 0
def c():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    start = 0
    end = K
    mark = sum(A[start:end])

    for i in range(end, N):
        prev_head = i - K
        curr_tail = i
        new_mark = mark - A[prev_head] + A[curr_tail]

        if new_mark > mark:
            print('Yes')
        else:
            print('No')

        mark = new_mark


##########
if __name__ == "__main__":
    c()


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

typedef long long ll;

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

    string s,t;cin>>s>>t;
    int q,slen=s.length(),tlen=t.length();cin>>q;
    vector<ll> scnt(slen+1,0),tcnt(tlen+1,0);
    if(s[0]=='A') scnt[1]=2;
    else scnt[1]=1;

    if(t[0]=='A') tcnt[1]=2;
    else tcnt[1]=1;

    for(int i=1;i<slen;i++){
        if(s[i]=='A') scnt[i+1]=scnt[i]+2;
        else scnt[i+1]=scnt[i]+1;
    }
    for(int i=1;i<tlen;i++){
        if(t[i]=='A') tcnt[i+1]=tcnt[i]+2;
        else tcnt[i+1]=tcnt[i]+1;
    }
    for(int i=0;i<q;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        if((scnt[b]-scnt[a-1])%3==(tcnt[d]-tcnt[c-1])%3) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


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

#define int long long

using namespace std;

long long dist(pair<int, int>& a, pair<int, int>& b){
  return abs(a.first - b.first) + abs(a.second - b.second);
}

long long cross(pair<int, int>& a, pair<int, int>& b, pair<int, int>& c){
  return (b.first - a.first) * (b.second - c.second) - (b.second - a.second) * (b.first - c.first);
}

vector<pair<int, int>> convex_hull(vector<pair<int, int>> ps){
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<pair<int, int>> ch(2 * n);
  for(int i = 0; i < n; ch[k++] = ps[i++]){
    while(k >= 2 && cross(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  }
  for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]){
    while(k >= t && cross(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  }
  ch.resize(k - 1);
  return ch;
}

signed main(){
  int N;
  cin >> N;
  
  vector<pair<int, int>> ps(N);
  set<pair<int, int>> s;
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    ps[i] = {x, y};
    s.insert(ps[i]);
  }
  
  if(s.size() <= 2){
    cout << dist(ps[0], ps[1]) << endl;
    return 0;
  }
  
  vector<pair<int, int>> ch = convex_hull(ps);
  
  int k = ch.size();
  
  long long max_dist = 0;
  for(int i = 0, r = 0; i < k; i++){
    while(dist(ch[i], ch[(r + 1) % k]) >= dist(ch[i], ch[r % k])) ++r;
    max_dist = max(dist(ch[i], ch[r % k]), max_dist);
    if(i == r) ++r;
  }
  
  cout << max_dist << endl;
  
  return 0;
}

Measured memory_bytes: 28284
def check():
    N = int(input())
    H = [int(i) for i in input().split()]
    
    max_h = 0
    
    for h in H:
        if max_h-1 > h:
            return 'No'
        if max_h <= h-1:
            max_h = h
    return 'Yes'
  
print(check())

Measured memory_bytes: 14252
N = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(N):
    s = list(str(input()))
    if s[0] == "M":
        m+=1
    elif s[0] == "A":
        a+=1
    elif s[0] == "R":
        r+=1
    elif s[0] == "C":
        c+=1
    elif s[0] == "H":
        h+=1
    else:
        pass
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)
        

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	
	char S[3];
	scanf("%s", S);

	int ans = 700;
	if (S[0] == 'o')ans += 100;
	if (S[1] == 'o')ans += 100;
	if (S[2] == 'o')ans += 100;

	printf("%d", ans);




}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define N 100034
#define M 256101

int n, e;
int u, v, i;
int to[M], first[N], next[M];

inline void addedge(int u, int v){
    to[++e] = v; next[e] = first[u]; first[u] = e;
    to[++e] = u; next[e] = first[v]; first[v] = e;
}

int dfs(int x, int px){
    int i, y, scx = 0;
    for(i = first[x]; i; i = next[i])
        if((y = to[i]) != px)
            if((scx += dfs(y, x)) >= 2)
                return 2;
    return !scx;
}

int main(){
    scanf("%d", &n);
    for(i = 1; i < n; ++i){
        scanf("%d%d", &u, &v);
        addedge(u, v);
    }
    puts(dfs(1, 0) ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 2176