akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
use std::collections::VecDeque;
use std::cmp::min;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let H:usize = sc.read();
    let W:usize = sc.read();
    let K:usize = sc.read();
    let A: Vec< Vec<char>> = (0..H).map(|_| sc.chars()).collect();

    let mut V: Vec< Vec<usize>> = vec![ vec![K+1;W];H];
    let mut q: VecDeque< (usize, usize)> = VecDeque::new();
    let mut m:usize = H;
    for i in 0..H{
        for j  in 0..W{
            if A[i][j] == 'S' {
                V[i][j] = 0;
                q.push_back((i, j));
                m = min(m, i);
                m = min(m, H-1-i);
                m = min(m, j);
                m = min(m, W-1-j); 
                break;
            }
        }
        if !q.is_empty(){
            break;
        }
    }
    while let Some((u, v)) = q.pop_front(){
        let t = V[u][v];
        if 0 < u{
            if (A[u-1][v] == '.') && (V[u-1][v] == K+1){
                V[u-1][v] = t+1;
                m = min(m, u-1);
                if t+1 < K{
                    q.push_back((u-1,v))
                }
            }
        }
        if u < H-1{
            if (A[u+1][v] == '.')&&(V[u+1][v] == K+1) {
                V[u+1][v] = t+1;
                m = min(m, H-1-(u+1));
                if t+1 < K{
                    q.push_back((u+1,v));
                }
            }
        }
        if 0 < v{
            if (A[u][v-1] == '.') && (V[u][v-1] == K+1){
                V[u][v-1] = t+1;
                m = min(m, v-1);
                if t+1 < K{
                    q.push_back((u,v-1))
                }
            }
        }
        if v < W-1{
            if (A[u][v+1] == '.')&&(V[u][v+1] == K+1) {
                V[u][v+1] = t+1;
                m = min(m, W-1-(v+1));
                if t+1 < K{
                    q.push_back((u,v+1));
                }
            }
        }
    }
    if m == 0{
        println!("1");
        return
    }else{
        println!("{}", (m+(K-1))/K+1);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 12668
#include <stdio.h>

#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

int h,w;
int mt[26][4]; //[i][0]:¶[ [1]:E[ [2]:ã[ [3]:º[
int used[26];
char t[54][54];

//(a+'A') Ì¶ª (b+'B') Ì¶æèOÉ é©Ì»è
//»Ì»èÆ¯É, a ª·û`Å é©à»è·é
int isFront(int a,int b){
	int i,j;
	REP(i,mt[a][2],mt[a][3]+1){
		REP(j,mt[a][0],mt[a][1]+1){
			if(t[i][j] == b + 'A' || t[i][j] == '.'){
				return 0;
			}
		}
	}
	return 1;
}

//SafeÅ é©Ç¤©Ì»è
int isSafe(int idx,int rem){
	int i,j;
	int okFlg;

	if(rem == 0){
		//ÅãÌLª·û`©»è·é½ßÉisFrontðg¤
		return isFront(idx,-1);
	}

	used[idx] = 1;
	rep(i,26){
		if(mt[i][1]!=-1 && !used[i]){

			//¡ÜÅgpµ½LSÄæèãëÉ é©»è
			okFlg = 1;
			rep(j,26) if(used[j] && !isFront(j,i)){
				okFlg = 0;
				break;
			}

			if(okFlg && isSafe(i,rem-1)) return 1;
		}
	}
	used[idx] = 0;

	return 0;
}

int main(void){
	int i,j;
	int n,idx,count;

	scanf("%d",&n);
	while(n--){
		scanf("%d%d",&h,&w);

		rep(i,26){
			mt[i][0] = w+1;
			mt[i][1] = -1;
			mt[i][2] = h+1;
			mt[i][3] = -1;
		}

		count = 0;
		rep(i,h){
			scanf("%s",t[i]);
			rep(j,w) if(t[i][j] != '.') {
				idx = t[i][j] - 'A';

				//LÌíÞJEg
				if(mt[idx][1] == -1) count++;

				//LÌ¶[,E[,ã[,º[ðXV
				if(mt[idx][0] > j) mt[idx][0] = j;
				if(mt[idx][1] < j) mt[idx][1] = j;
				if(mt[idx][2] > i) mt[idx][2] = i;
				if(mt[idx][3] < i) mt[idx][3] = i;
			}
		}

		rep(i,26) used[i] = 0;
		rep(i,26) if(mt[i][1] != -1 && isSafe(i,count-1)) break;

		printf("%s\n",count!=0 && i==26 ? "SUSPICIOUS" : "SAFE");
	}

	return 0;
}

Measured memory_bytes: 384
N = int(input())
l =[]
a=0
b=0
c=0
d=0
for i in range(N):
  l.append(input())
for i in range(N):
  if l[i]=="AC":
    a = a+1
  elif l[i]=="WA":
    b = b+1
  elif l[i]=="TLE":
    c = c+1
  else:
    d = d+1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d)


Measured memory_bytes: 16320
import java.util.*;
public class Main{

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

      for(int i = 2; i >= 0; i--)
        if(m.charAt(i) != n.charAt(2-i)) {
            System.out.println("NO");
            return;
        }

      System.out.println("YES");
  }
}



Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define MAXN 2020
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
typedef pair<int, int> ii;
typedef long long ll;

int dp[20][200][2], sz;
char w[20];

int calc(int digit, int sum, int isLess) {
	if (digit == sz) return sum;
	int& ans = dp[digit][sum][isLess];
	if (ans != -1) return ans;

	int maxV = isLess ? 9 : w[digit]-'0';
	ans = 0;
	for (int i = 0; i <= maxV; i++) {
		ans = max(ans, calc(digit+1, sum + i, isLess|(i < maxV)));
	}
	return ans;
}
int main() {
	long long n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	sprintf(w, "%lld", n);
	sz = strlen(w);

	cout << calc(0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int X,N,i,j=1,q,r,Y1,Y2,a=1;
	cin>>X>>N;
	int p[N];
	for(i=0;i<N;i++){
		cin>>p[i];
		if(p[i]==X){
			a=0;
			
		}
	}
	if(a!=0){
		cout<<X<<endl;
	}
	while(a<1){
		Y1=X-j;
		q=0;
		r=0;
		for(i=0;i<N;i++){
			if(p[i]==Y1){
				q=1;
			}
		}
		Y2=X+j;
		for(i=0;i<N;i++){
			if(p[i]==Y2){
				r=1;
			}
		}
		j++;
		if(q==0){
			cout<<Y1<<endl;
			break;
		}
		if(r==0&&q!=0){
			cout<<Y2<<endl;
			break;
		}
	}
}
	
		
				
			

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

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int Min(vector<long> x){
  int a=x.size();
  for(int i=0;i<a-1;i++){
    x.at(i+1)=min(x.at(i),x.at(i+1));
  }
  return x.at(a-1);
}

long long f(vector<long> x){
  long long ans=0;
  for(int i=0;i<x.size();i++){
    ans+=x.at(i);
  }
  return ans;
}

int main() {
  int N,c;
  cin>>N;
  vector<long> a(N);
  Bint ans=0;
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    if(a.at(i)<0){
      c++;
      a.at(i)=labs(a.at(i));
    }
  }
  //  cout<<a.at(0)<<Min(a);
  ans=f(a);
  if(c%2==1){
    ans-=2*Min(a);
  }
  //Bint X=10000000*100000;
  cout<<ans;
  return 0;
}



Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define N 1000010
using namespace std;
int dp[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int k;
	cin>>k;
	dp[0]=0;
	for(int i=1;i<N;i++)
	{
		dp[i]=(dp[i-1]*10%k+7)%k;
		if(!dp[i])
		{
			cout<<i<<endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 7512
#include <iostream>
using namespace std;
long long n,sum=1;
int main() {
	// your code goes here
	cin>>n;

     
  
  
	for (int i=1;i<=n;++i)
	{
	    sum*=i;
	    sum%=(1000000000+7);
	}
    cout<<sum%(1000000000+7)<<endl;

	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
ans=10**9
w1,w2=w//2,w-w//2
for i in range(1,h):
  s=i*w,w1*(h-i),w2*(h-i)
  ans=min(ans,max(s)-min(s))
h1,h2=h//2,h-h//2
for i in range(1,w):
  s=i*h,h1*(w-i),h2*(w-i)
  ans=min(ans,max(s)-min(s))
if h%3==0 or w%3==0:
  ans=0
if w >2:
  ans=min(ans,w)
if h >2:
  ans=min(ans,h)
print(ans)

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

using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
const int INF = 1<<31;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int LL;

int x;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

    cin >> x;

    if(x<1200)
        cout << "ABC";
    else
        cout << "ARC";

    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);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		long sum = 0;
		for (int i = n - 1; i >= 0; i--) {
			if ((a[i] + sum) % b[i] != 0) {
				sum += b[i] - ((a[i] + sum) % b[i]);
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 88704
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> t(n+1);
  vector<pair<int,int>> xy(n+1);
  int i;
  t.at(0)=0;
  xy.at(0)=make_pair(0,0);
  rep(i,n){
    cin >> t.at(i+1);
    int a,b;
    cin >> a >> b;
    xy.at(i+1)=make_pair(a,b);
  }
  string s="Yes";
  
  rep(i,n){
    int count_1=t.at(i+1)-t.at(i),count_2=abs(xy.at(i+1).first-xy.at(i).first);
    int count_3=abs(xy.at(i+1).second-xy.at(i).second);
    int count_4=count_2+count_3;
    if(count_4>count_1){
      s="No";
    }
    if((count_1+count_4)%2==1){
      s="No";
    }
  }
  cout << s;
}
    
    
  


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

int main() {
    int n, X;
    cin >> n >> X;
    int x[n + 1];
    rep(i, n) cin >> x[i];
    x[n] = X;

    int d[n];
    sort(x, x + n + 1);
    rep(i, n) d[i] = x[i + 1] - x[i];

    int ans = d[0];
    for (int i = 1; i < n; i++) {
        ans = __gcd(ans, d[i]);
    }

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


Measured memory_bytes: 1024
#!/usr/bin/env python3
#ABC109 B

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

if len(list(set(w))) != n:
    print('No')
    quit()
for i in range(n-1):
    if list(w[i])[-1] == list(w[i+1])[0]:
        continue
    else:
        print('No')
        quit()
print('Yes')


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll T, X;
  cin >> T >> X;

  cout << fixed << setprecision(15) << T / (double)X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n;
int a[1005][1005];
int main(void){
    cin>>n;
    for(int k=2;k*(k-1)<=n*2;k++){
        if(k*(k-1)==n*2){
            cout<<"Yes\n";
            cout<<k<<endl;
            int p=1;
            for(int i=0;i<k-1;i++){
                for(int j=i;j<k-1;j++){
                    a[i][j]=p;
                    a[j+1][i]=p;
                    p++;
                }
            }
            for(int i=0;i<k;i++){
                cout<<k-1<<' ';
                for(int j=0;j<k-1;j++){
                    cout<<a[i][j];
                    if(j!=k-2)cout<<' ';
                }
                cout<<endl;
            }
            return 0;
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a+b < b+c && a+b < a+c){
            System.out.println(a+b);
        }else if(a+b > b+c && a+c > b+c){
            System.out.println(b+c);
        }else{
            System.out.println(a+c);
        }
    }
}

Measured memory_bytes: 21460
N, X, Y = map(int, input().split())
X -= 1; Y -= 1

pat = [0]*(N-1)

for i in range(N):
  for j in range(i+1, N):
    d = min(abs(i-j), abs(X-i)+1+abs(j-Y))
    pat[d-1] += 1

for i in range(N-1):
  print(pat[i])

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

  ll arr[5] ;
  for(i=0;i<5;i++)
    cin>>arr[i] ;
  for(i=0;i<5;i++)
  {

      if(arr[i]==0)
        break ;
  }
  cout<<i+1 ;
  return 0; }


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int E,Count;
int solve(int E);

int solve(int E) {
  int x,y,z;
  int min = E;
  for (z=0;z*z*z<=E;z++) {
    for (y=0;y*y<=E-z*z*z;y++) {
      x = E-z*z*z-y*y;
      Count++;
      if (x>=0 && x+y+z<min) {
	min = x+y+z;
      }
    }
  }
  return min;
}
int main() {
  while (cin >> E && E>0) {
    //  cout << "min  : " << solve(E) << endl
    // << "count: " << Count << endl;
    cout << solve(E) << endl;
  }
}

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

using ll=long long;



void solve(){
    string s;
    cin>>s;
    for(int i=0; i<s.size()-1; i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
double be(double a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod)); else return (be(a,b/2,mod)*be(a,b/2,mod));}
const int mod = 1e9 + 7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
const int siz = 2*(1e6 + 10);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
int has[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


signed main()
{
	#ifndef ONLINE_JUDGE
 	freopen("in.txt", "r", stdin);
 	freopen("out.txt", "w", stdout);
 	#else
// // online submission
 	#endif 
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{	
		int x;
		cin>>x;

		double rate = 1.01;

		int cnt = 0;
		double p = 100;
		while(true)
		{
			cnt++;
			double newval = p*rate;

			int newp = newval;
			p = newp;
			//cout<<p<<"\n";
			if(p >= x)
			{
				break;
			}
		}

		cout<<cnt<<"\n";
	}
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

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

	int cnt0 = 0, cnt1 = 0;
	REP(i, strlen(s)) {
		if (s[i] == '0') cnt0++;
		if (s[i] == '1') cnt1++;
	}
	PRINTD(Min(cnt0, cnt1) * 2);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    pair<int,bool> a[3][3];
    for(int i = 0;i < 3;i++)
    {
        for(int j = 0;j < 3;j++)
        {
            cin >> a[i][j].first;
            a[i][j].second = false;
        }
    }
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        int b;
        cin >> b;
        for(int j = 0;j < 3;j++)
        {
            for(int k = 0;k < 3;k++)
            {
                if(a[j][k].first == b)
                {
                    a[j][k].second = true;
                }
            }
        }
    }
    bool flag = false;
    for(int i = 0;i < 3;i++)
    {
        if(a[i][0].second && a[i][1].second && a[i][2].second)
        {
            flag = true;
            break;
        }
        else if(a[0][i].second && a[1][i].second && a[2][i].second)
        {
            flag = true;
            break;
        }
    }
    if(a[0][0].second && a[1][1].second && a[2][2].second || a[0][2].second && a[1][1].second && a[2][0].second)
    {
        flag = true;
    }
    if(flag)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <cmath>
#include <map>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define decn int n = 0; cin >> n
#define sort(v) sort(v.begin(), v.end())
#define in(type, n) type n = 0; cin >> n

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

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

	int a[h][w];
	int b[h][w];
	rep(i, h) {
		rep(j, w) {
			char c;
			cin >> c;
			if (c == '#') {
				a[i][j] = 1;
			} else {
				a[i][j] = 0;
			}
			b[i][j] = 0;
		}
	}

	rep(i, h+w-1) {
		for (int j = ((w - i > 0) ? 0 : i - w + 1); j < min(i+1, h); j++) {
			if (j == 0 && i == 0) {
				if (a[0][0] == 1) {
					b[0][0] = 1;
					continue;
				}
				continue;
			}
			// 横
			if (i - j == 0) {
				if (a[j - 1][i-j] == 1 && a[j][i-j] == 1) {
					b[j][i-j] = b[j-1][i-j];
					continue;
				}
				if (a[j][i-j] == 1) {
					b[j][i-j] = b[j-1][i-j] + 1;
					continue;
				}
				b[j][i-j] = b[j-1][i-j];
				continue;
			}
			// 縦
			if (j == 0) {
				if (a[j][i-j-1] == 1 && a[j][i-j] == 1) {
					b[j][i-j] = b[j][i-j-1];
					continue;
				}
				if (a[j][i-j] == 1) {
					b[j][i-j] = b[j][i-j-1] + 1;
					continue;
				}
				b[j][i-j] = b[j][i-j-1];
				continue;
			}
			int x = b[j-1][i-j];
			int y = b[j][i-j-1];
			if (a[j-1][i-j] != 1 && a[j][i-j] == 1) {
				x++;
			}
			if (a[j][i-j-1] != 1 && a[j][i-j] == 1) {
				y++;
			}
			b[j][i-j] = min(x, y);
			contin:;
		}
	}

	cout << b[h-1][w-1];

	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int pre[200005];

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,k;
    cin>>n>>k;
    int a[n+1];
    ordered_set<pair<int,int> >s;
    for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            pre[i]=pre[i-1]+a[i]-k;
            s.insert({pre[i],i});
        }
    int ans=0;
    int num=s.order_of_key({0,-1});
    ans+=s.size()-num;
    for(int i=2;i<=n;i++)
    {
        s.erase({pre[i-1],i-1});
        num=s.order_of_key({pre[i-1],-1});
        int sz=s.size();
        ans+=sz-num;
    }
    cout<<ans;



} 



Measured memory_bytes: 15872
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	ll r;
  re(r);
  prln(r*r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int h, w; cin >> h >> w;
	vs fld(h); cin >> fld;
	vector<vi> d(h, vi(w, -1));
	d[0][0] = 0;
	queue<pii> que;
	que.emplace(0, 0);
	while (!que.empty())
	{
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		REP(i, 4)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!valid(nx, ny, h, w) || fld[nx][ny] == '#' || d[nx][ny] >= 0) continue;
			d[nx][ny] = d[x][y] + 1;
			que.emplace(nx, ny);
		}
	}
	int cnt = 0;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == '.') cnt++;
	}
	if (d[h - 1][w - 1] == -1) cout << -1 << endl;
	else cout << cnt - d[h - 1][w - 1] - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
const int oo=1073741819;
using namespace std;
int tail[200000],d[200000],g[200000],ru[200000],chu[200000],v[200000],p[200000];
int next[2000000],flow[2000000],sora[2000000],po[2000000],st[2000000];
int cost[2000000];
int n,m,s,t,ss;
bool spfa(int s,int t)
{
	int h,r,ne,na;
	for (int i=1;i<=t;i++) d[i]=oo;
	h=r=0;
	st[r=1]=s,d[s]=0,v[s]=1,p[s]=0;
	for (;h<r;) {
		ne=st[++h];
		for (int i=ne;next[i];) {
			i=next[i],na=sora[i];
			if (flow[i] && d[ne]+cost[i]<d[na]) {
				d[na]=d[ne]+cost[i],p[na]=i;
				if (!v[na]) {
					v[na]=1;
					st[++r]=na;
				}
			}
		}
		v[ne]=0;
	}
	return d[t]<oo;
}
int widen()
{
	int sum=0,d=oo;
	for (int i=t;i!=s;i=sora[po[p[i]]]) 
		d=min(d,flow[p[i]]);
	for (int i=t;i!=s;i=sora[po[p[i]]]) {
		sum+=d*cost[p[i]];
		flow[p[i]]-=d,flow[po[p[i]]]+=d;
	}
	return sum;
}
void origin()
{
	s=n+1,t=s+1,ss=t;
	for (int i=1;i<=t;i++) tail[i]=i,next[i]=0;
}
void link(int x,int y,int z,int w)
{
	++ss,next[tail[x]]=ss,tail[x]=ss,sora[ss]=y,flow[ss]=z,cost[ss]=w,next[ss]=0;
	++ss,next[tail[y]]=ss,tail[y]=ss,sora[ss]=x,flow[ss]=0,cost[ss]=-w,next[ss]=0;
	po[ss]=ss-1,po[ss-1]=ss;
}
void bfs(int s,int t)
{
	spfa(s,t);
	g[t]=-d[t];
}
int main()
{
	scanf("%d%d",&n,&m);
	origin();
	int tot=0;
	for (int i=1;i<=m;i++) {
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x++,y++;
		link(x,y,oo,-z);
		chu[x]++,ru[y]++;
		tot+=z;
	}
	bfs(1,n);
	for (int i=1;i<=n;i++)
		if (ru[i]>chu[i]) link(s,i,ru[i]-chu[i],0);
		else link(i,t,chu[i]-ru[i],0);
	link(n,1,oo,g[n]);
	int ans=0;
	for (;spfa(s,t);ans+=widen()) ;
	printf("%d\n",ans-tot);
	return 0;
}

Measured memory_bytes: 17588
#include <stdio.h>

#define TRUE 1
#define FALSE 0
#define MAX_LEN 5

int main(void)
{
	char S[MAX_LEN];
	int i, ok = TRUE;
	scanf("%s", S);

	for (i = 1; i < MAX_LEN; i++)
		if (S[i] == S[i - 1])
			ok = FALSE;
	puts(ok ? "Good" : "Bad");
	return 0;
}


Measured memory_bytes: 128
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			int n = sc.nextInt();
			Set<Integer> set = new HashSet<Integer>();
			int c = 0;
			while (true) {
				if (set.contains(n)) {
					c = -1;
					break;
				}
				if (n < 10) {
					break;
				}
				set.add(n);
				c++;
				String str = Integer.toString(n);
				int max = 0;
				for (int j = 1; j < str.length(); j++) {
					String str1 = str.substring(0, j);
					String str2 = str.substring(j, str.length());
					max = Math.max(max,
							Integer.parseInt(str1) * Integer.parseInt(str2));
				}
				n = max;
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
  long A, B;

  cin >> A >> B;

  A = A != 0 ? A-1 : 0;

  long scale = 1;
  long x_or = 0;

  while(scale <= B)
  {
    long A_scale_divided = A/scale;
    long B_scale_divided = B/scale;

    long num_one_at_digit_A = long(A_scale_divided/2)*scale + long(A_scale_divided%2)*(A%scale + 1);
    long num_one_at_digit_B = long(B_scale_divided/2)*scale + long(B_scale_divided%2)*(B%scale + 1);

    x_or += (num_one_at_digit_B - num_one_at_digit_A)%2*scale;
    scale*=2;
  }

  cout << x_or << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
#define AsceSort(a) sort(a.begin(),a.end())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 != 0) {
		cout << "Yes" << endl;
	}
	else 
		cout << "No" << endl;
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = Integer.parseInt(s.next());
        int a = 0,t = 0,w = 0,r = 0;
        while(n-->0){
            String str = s.next();

            switch (str) {
                case "AC":
                    a++;
                    break;
                case "RE":
                    r++;
                    break;
                case "TLE":
                    t++;
                    break;
                case "WA":
                    w++;
                    break;
            }
        }
        System.out.println("AC x "+a);
        System.out.println("WA x "+w);
        System.out.println("TLE x "+t);
        System.out.println("RE x "+r);
    }
}


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

string s;
int n, mod = 1000000007;

long long mem[5042][5042];

long long solve ( int left, int ok ) {
    if ( left == 0 ) {
        if ( ok == s.size() ) { return 1; }
        return 0;
    }
    if ( mem[left][ok] ) { return mem[left][ok]-1; }
    long long ret = 0;

    ret += 2*solve( left-1, ok+1 );
    ret += solve ( left-1, max( ok-1, 0 ) );
    ret %= mod;

    mem[left][ok] = ret+1;
//    cout << left << " " << wrong << " " << ind << " : " <<
    return ret;
}
string getS ( int x ) {
    string ret = "";
    for ( int i = 0 ; i < x ; i ++ ) { ret += "1"; }
    return ret;
}
long long pow2( long long a, long long st ) {
    long long ret = 1;
    for ( ; st ; st /= 2 ) {
        if ( st&1 ) {
            ret *= a;
            ret %= mod;
        }
        a *= a;
        a %= mod;
    }
    return ret;
}

int main () {

    cin >> n;
    cin >> s;
    long long cans = solve ( n, 0 );
    for ( int i = 0 ; i < s.size() ; i ++ ) {
        cans *= pow2( 2, mod-2 );
        cans %= mod;
    }
    cout << cans << "\n";

    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i=0; i<H; i++) {
    cin >> a.at(i);
  }
  string s;
  for (int i=0; i<W+2; i++) {
    s += "#";
  }
  cout << s << endl;
  for (int i=0; i<H; i++) {
    cout << "#"+a.at(i)+"#" << endl;
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#import<iostream>
#import<string>
using namespace std;typedef long long l;
l f(l n){return n? n*f(n-1):1;}int main(){string s;cin>>s;int m[256]={0},i,b=1,n=0,c;for(i=0;i<s.size();i++)m[s[i]]++;l a=f(s.size()/2);for(c=97;c<123;c++)if(m[c]%2)n++;if(n>s.size()%2)b=0;if(b)for(c=97;c<123;c++)a/=f(m[c]/2);cout<<(b?a:0)<<endl;}

Measured memory_bytes: 0
/**
  *  Worg
  */
#include <vector>
#include <iostream>
#include <algorithm>

const int MOD = 1e9 + 7;

void fix(int& value) {
	if (value >= MOD) {
		value -= MOD;
	}
}

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::vector<char>> a(n, std::vector<char>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			std::cin >> a[i][j];
		}
	}

	std::vector<std::vector<int>> dp(n, std::vector<int>(m, 0));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j] == '#') {
				dp[i][j] = 0; continue;
			}

			if (i == 0 && j == 0) {
				dp[i][j] = 1;
			} else if (i == 0) {
				dp[i][j] = dp[i][j - 1];
			} else if (j == 0) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				fix(dp[i][j]);
			}
		}
	}

	std::cout << dp[n - 1][m - 1] << "\n";
	return 0;
}

Measured memory_bytes: 5248
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N;
ll Prime_Count[100] = {}, Count[100] = {};

int main(){
  cin >> N;
  for (int i = 2; i <= N; i++){
    int num = i;
    for (int j = 2; j <= i; j++){
      while (num % j == 0){
        Prime_Count[j]++;
        num /= j;
      }
    }
  }

  
  for (int i = 0; i < 100; i++){
    Count[Prime_Count[i]]++;
  }
  
  for (int i = 98; i >= 0; i--){
    Count[i] += Count[i + 1];
  }


  ll ans = Count[74];
  ans += Count[24] * (Count[2] - 1);
  ans += Count[14] * (Count[4] - 1);
  ans += Count[4] * (Count[4] - 1) * (Count[2] - 2) / 2;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define pq priority_queue
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 3e3 + 5;

int lcs;
int dp[N][N];
string s, t;
vt<char> v;

int f(int a, int b) {
    if(a == s.size() || b == t.size()) return 0;
    int &sol = dp[a][b];
    if(sol != -1) return sol;
    if(s[a] == t[b]) return sol = 1 + f(a + 1, b + 1);
    return sol = max(f(a + 1, b), f(a, b + 1));
}

void backtrack(int a, int b) {
    if(a == s.size() || b == t.size()) return;
    int temp = -INF, aplus, bplus;
    aplus = f(a + 1, b);
    bplus = f(a, b + 1);
    if(s[a] == t[b])
        temp = f(a + 1, b + 1);
    if(temp != -INF) {
        v.pb(s[a]);
        backtrack(a + 1, b + 1);
    } else if(aplus > bplus) 
        backtrack(a + 1, b);
    else 
        backtrack(a, b + 1);
}

void solve() {
    cin >> s >> t;
    memset(dp, -1, sizeof(dp));
    backtrack(0, 0);
    for(char x : v) 
        cout << x;
    cout << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

Measured memory_bytes: 39076
from collections import deque

def main():
    n, m = map(int, input().split())
    to = [[] for _ in range(n+1)]
    ans = [None]*(n+1)
    for _ in range(m):
        a, b = map(int, input().split())
        to[a].append(b)
        to[b].append(a)
    q = deque([1])
    while q:
        p = q.pop()
        children = to[p]
        for child in children:
            if ans[child] is None:
                ans[child] = p
                q.appendleft(child)
    print("Yes")
    print("\n".join(list(map(str, ans[2:]))))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 41652
N = int(input())
syougen = [[] for i in range(N)]
for i in range(N):
    a_tmp = int(input())
    for j in range(a_tmp):
        [x, y] = list(map(int,input().split()))
        syougen[i].append([x-1,y])
ans = 0
for i in range(2**N):
    data = [0]*N
    for j in range(N):
        if ((i >> j) & 1):
            data[j] = 1
    flag = True
    for k in range(N):
        if data[k] == 1:
            for l in range(len(syougen[k])):
                x = syougen[k][l][0]
                y = syougen[k][l][1]
                if data[x] != y:
                    flag = False
    if flag:
        ans = max(ans,sum(data))
print(ans)        

Measured memory_bytes: 3064
x, n = map(int, input().split())
if n == 0:
	print(x)
	exit()
p = list(map(int, input().split()))

s = set(p)
p = []
for x1 in range(-100, 200):
	if x1 in s:
		continue
	else:
		p.append(x1)
mind = abs(x - p[0])
pos = [p[0]]
for q in p:
	if abs(x - q) < mind:
		#print(q)
		mind = abs(x - q)
		pos = [q]
	elif abs(x - q) == mind:
		pos.append(q)
pos.sort()
print(pos[0])

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
const int mod = 1e9 + 7;
inline int mul( int x , int y ){ return 1LL * x * y % mod ;}
int power_mod( int x , int y ){int ret = 1;while( y ){if( y & 1 ) ret = mul( ret , x );y >>= 1;x = mul( x , x );}return ret;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std;
const int maxn = 1e3 + 50;
const double pi = acos( -1 );

int stx , sty , edx , edy , n , r[maxn];
pair < int , int > p[maxn];
vector < pair < int , double > > G[maxn];

void Link( int u , int v , double c ){
	G[u].push_back( make_pair( v , c ) );
	G[v].push_back( make_pair( u , c ) );
}

long long sqr( int x ){
	return 1LL * x * x;
}

double cal( int x , int y ){
	if( sqr( r[y] + r[x] ) >= sqr( p[x].first - p[y].first ) + sqr( p[x].second - p[y].second ) )
		return 0;
	else
		return hypot( p[x].first - p[y].first , p[x].second - p[y].second ) - r[x] - r[y];
}

double cal( int x , int y , int id ){
	if( sqr( x - p[id].first ) + sqr( y - p[id].second ) <= sqr( r[id] ) )
		return 0;
	else
		return hypot( x - p[id].first , y - p[id].second ) - r[id];
}

struct Node{
	int x ;
	double v ;

	friend bool operator < ( const Node & a , const Node & b ){
		return a.v > b.v;
	}

	Node( int x , double v ) : x(x) , v(v){}
};

double dp[maxn];
__gnu_pbds::priority_queue < Node > pq;
__gnu_pbds::priority_queue < Node > :: point_iterator pf[maxn];

int main(int argc,char *argv[]){
	stx = read() , sty = read() , edx = read() , edy = read() , n = read();
	for(int i = 1 ; i <= n ; ++ i){
		p[i].first = read() , p[i].second = read() , r[i] = read();
	}
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j < n ; ++ j){
			double dis = cal( i , j );
			Link( i , j , dis );
		}
	for(int i = 1 ; i <= n ; ++ i){
		double dis = cal( stx , sty , i );
		Link( 0 , i , dis );
		dis = cal( edx , edy , i );
		Link( n + 1 , i , dis );
	}
	double dis = hypot( stx - edx , sty - edy );
	Link( 0 , n + 1 , dis );
	for(int i = 1 ; i <= n + 1 ; ++ i)
		dp[i] = 1e233;
	pf[0] = pq.push( Node( 0 , 0 ) );
	while(!pq.empty()){
		Node s = pq.top() ; pq.pop();
		int x = s.x ;
		double fq = s.v;
		for(auto go : G[x]){
			int v = go.first ;
			double cost = go.second;
			if( cost + fq < dp[v] ){
				if( dp[v] > 1e200 ){
					dp[v] = cost + fq;
					pf[v] = pq.push( Node( v , dp[v] ) );
				}
				else{
					dp[v] = cost + fq;
					pq.modify( pf[v] , Node( v , dp[v] ) );
				}
			}
		}
	}
	printf( "%.12lf\n" , dp[n + 1] );
	return 0;
}

Measured memory_bytes: 32640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a = 0,b = 0,c = 0;
    int n = len(s);
    rep(i,n){
        if(s[i] == 'a'){
            a++;
        }else if(s[i] == 'b'){
            b++;
        }else{
            c++;
        }
    }
    if(abs(a-b) <= 1 && abs(b-c) <= 1 && abs(c-a) <= 1){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
 
using namespace std;

int main(){
  int n;
  cin >> n;
  int ans=0;
  int h=0;
  
  for(int i=0;i<n;i++){
    int a;
    cin >>a;
    if(a>=h) ans++;
    h=max(h,a);
  }
  cout <<ans<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
 
int main()
{
    int N, M;
    scanf("%d %d", &N, &M);

    int cnt=0,st=0,end;
    int st2, end2;
    int max_dist = M;
    int dist = max_dist;
    while(cnt<M){
        end = st+dist;
        st2 = st+M+1; end2=st2+dist-1;
        printf("%d %d\n", st+1, end+1);
        cnt++;
        if(cnt==M) break;

        printf("%d %d\n", st2+1, end2+1);
        cnt++;
        st++;
        dist -= 2;
    }
    return 0;
}

Measured memory_bytes: 3788
def resolve():
    from collections import deque
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = deque()
    for i in range(N):
        if i % 2 == 0:
            ans.append(A[i])
        else:
            ans.appendleft(A[i])
    if i % 2 == 0:
        print(*list(ans)[::-1])
    else:
        print(*ans)


resolve()


Measured memory_bytes: 32188
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    vector<int> x(1000, 0);

    for (int i = 1; i < 1000; ++i) {
        x[i] += x[i-1] + i;
    }

    int n = b - a;
    cout << x[n] - b << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
_=int(input())
A=list(map(int,input().split()))
N=len(A)

trend=0
ans=0
for i in range(N-1):
    temp=A[i+1]-A[i]
    if trend==0:
        if temp>0:
            trend=1
            ans+=1
        elif temp<0:
            trend=-1
            ans+=1
        else:
            pass
    elif trend==1:
        if temp>0:
            pass
        elif temp<0:
            trend=0
        else:
            pass
    elif trend==-1:
        if temp>0:
            trend=0
        elif temp<0:
            pass
        else:
            pass

print(ans if trend!=0 else ans+1)


Measured memory_bytes: 14252
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int INF = 0x3f3f3f3f;


int n;
int ans,res,no;
int d[11][11];
int V;

int main()
{
	while(cin>>n)
	{
		if(n==0)
		{
			return 0;
		}
		memset(d,INF,sizeof(d));
		for(int i = 0;i < 11;i++)
		{
			d[i][i] = 0;
		}
		V = 0;ans = INF;
		for(int i = 1;i <= n;i++)
		{
			int a,b,c;
			cin>>a>>b>>c;
			d[a][b] = c;
			d[b][a] = c;
			V = max(V,max(a,b) + 1);   
		}
		for(int k = 0;k < V;k++)
		{
			for(int i = 0;i < V;i++)
			{
				for(int j = 0;j < V;j++)
				{
					d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
				}
			}
		}
		for(int i = 0;i < V;i++)
		{
			res = 0;
			for(int j = 0;j < V;j++)
			{
				res = res + d[i][j];
			}
			if(res < ans)
			{
				ans = res;
				no = i;
			}
		}
		cout<<no<<" "<<ans<<endl;
	}
} 


Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define ld  double
#define ll long long 
#define pp push
#define pb push_back
#define pf push_front
#define mp make_pair
#define inf 1e9
#define f first
#define s second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define mod 1000000007
using namespace std; 
int main()
{
    ll dp[100007];
    memset(dp,mod,sizeof(dp));
    ll n,w;
    cin>>n>>w;
    ll v1[100009],w1[100009];
    ll val=0;
    for(ll i=0;i<n;i++)
    {
       cin>>w1[i]>>v1[i];
       val+=v1[i];
    }
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        ll t1=v1[i];
        ll t2=w1[i];
        for(ll j=val;j>=t1;j--)
        {
          dp[j]=min(dp[j],dp[j-t1]+t2);  
          //cout<<"dp["<<j<<"]="<<dp[j]<<endl;
        }
    }
    for(int i = val;i>=0;i--)
    {
		if(dp[i] <= w)
		{
			cout << i << endl;
			break;
		}
	}
}

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

int main() {
	long n, m;
	cin >> n >> m;
	vector<long> a(m);
	long total = 0;
	long error = -1;
	for (int i = 0; i < m; i++) {
		cin >> a.at(i);
		total += a.at(i);
	}
	if (n >= total) cout << n - total << endl;
	else cout << error << endl;
}

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


int main(){
  
  string s;
  cin >> s;
  
  if(s=="ARC")
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  
  
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(){
	int k,cnt,a;
	scanf("%d",&k);
	if(k%2==0||k%10==5) {
		printf("-1\n");
		return 0;
	}
	a=7,cnt=1;
	while(1){
		if(a%k==0)break;
		a%=k,a=a*10+7,cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main() {
int a,b,c,d;
  cin >> a >> b >> c >> d;
  int L=a+b;
  int R=c+d;
  if(L>R){
    cout << "Left" << endl;
  }
    if(L<R){
      cout << "Right" << endl;
    }
  if(L==R){
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3556
using System;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);
        int c = int.Parse(s[2]);
        b = Math.Abs(a - b);
        c = Math.Abs(a - c);
        string ans = "A";
        if (b > c) ans = "B";
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
loc = []
for i in range(5):
    loc.append(int(input()))
k = int(input())

from itertools import combinations as comb
loc_comb = list(comb(loc, 2))

check = True

for i in range(len(loc_comb)):
    dis = abs(loc_comb[i][0] - loc_comb[i][1])
    if dis > k:
        check = False
        break

if check:
    print("Yay!")
else:
    print(":(")

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

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

    int S_len = S.length();
    if(K >= S_len)cout<<S<<endl;
    else
    {
        for(int i = 0; i < K + 3; i++)
        {
            if(i < K)cout<<S[i];
            else
            {
                cout<<'.';
            }
            
        }
        cout<<endl;

    }
    return 0;
    
}

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

using namespace std;
long bi(long num);

int main(void){
	long N;
	std::vector<long> ai;
	std::cin>>N;

	long ans = 0;
	for(int i=0;i<N;i++){
		long a;
		std::cin>>a;
		long ari = bi(a);
		ai.push_back(a);
		ans += ari;
	}

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

long bi(long num){
	long cnt = 0;
	int amari = 0;

	while(amari == 0){
		amari = num % 2;
		num /= 2;
		cnt++;
	}
	cnt--;
	return cnt;
}


Measured memory_bytes: 512