akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	  public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int[] list = new int[n];
	    
	    for (int i = 0; i < list.length; i++) {
			list[i] = sc.nextInt();
		}
	    
	    int cnt = 1;
	    int min = list[0];
	    for (int i = 1; i < list.length; i++) {
			 if (min >= list[i]) {
				 cnt++;
				 min = list[i];
			 }
		}
	    
	    
	    System.out.println(cnt);
	    
	  }
	}

Measured memory_bytes: 64628
time = 0
a = int(input())
b= int(input())
c = int(input())
d = int(input())
e = int(input())
lis = [a,b,c,d,e]
for num in lis:
    time += num
amarilis = []
for item in lis:
    if item % 10 == 0:
        amarilis.append(0)
    else:
        amarilis.append(10 -(item % 10))


amarilis.sort()

del amarilis[4]

for nu in amarilis:
    time += nu
print(time)



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

int main() {
    int x;
    cin>>x;
    int y;
    rep(i,(x/105)+2){
        y=x-(105*i);
        rep(j,(y/104)+2){
            y=x-(105*i)-(104*j);
            rep(k,(y/103)+2){
                y=x-(105*i)-(104*j)-(103*k);
                rep(l,(y/102)+2){
                    y=x-(105*i)-(104*j)-(103*k)-(102*l);
                    rep(m,(y/101)+2){
                        y=x-(105*i)-(104*j)-(103*k)-(102*l)-(101*m);
                        if(y%100==0 && y>=0){
                            cout<<1<<endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout<<0<<endl;
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

vi devideA(vi A, int p){
    vi ret_A;
    REP(i, 0, A.size()){
        
    }
    return ret_A;
}
int gcd(long long a, long long b){
    if(a%b == 0) return b;
    return gcd(b, a%b);
}

int main() {
    int N;
    cin>>N;
    vi A(N), L(N), R(N);
    REP(i, 0, N) cin >> A[i];
    L[0] = A[0]; R[N-1] = A[N-1];
    REP(i, 0, N-1){
        L[i+1] = gcd(L[i], A[i+1]);
        R[N-2-i] = gcd(R[N-1-i], A[N-2-i]);
    }
    int ans = 0;
    REP(i, 0, N){
        if(i == 0) ans = max(ans, R[1]);
        else if(i == N-1) ans = max(ans, L[N-2]);
        else ans = max(ans, gcd(L[i-1], R[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static final int P = 1_000_000_007;

	int[] goNoEmpty(int n, int k) {
		int[] ret = new int[n + 1];
		int[] dp = { 1 };
		int p2 = 1;
		for (int i = 1; i <= n; i++) {
			int[] nxt = new int[i + 1];
			for (int j = 1; j <= i; j++) {
				nxt[j] = (dp[j - 1] + (j + 1 < i ? dp[j + 1] : 0)) % P;
			}
			dp = nxt;
			if (i >= k && (i - k) % 2 == 0) {
				ret[i] = (int) ((long) dp[k] * p2 % P);
				p2 = 2 * p2 % P;
			}
		}
		return ret;
	}
	
	int[] goEmpty(int n) {
		int[] ret = new int[n + 1];
		ret[0] = 1;
		int[] dp = { 1 };
		for (int i = 1; i <= n; i++) {
			int[] nxt = new int[i + 1];
			nxt[0] = i == 1 ? 1 : (dp[0] + dp[1]) % P;
			for (int j = 1; j <= i; j++) {
				nxt[j] = (2 * dp[j - 1] % P + (j + 1 < i ? dp[j + 1] : 0)) % P;
			}
			dp = nxt;
			ret[i] = dp[0];
		}
		return ret;
	}

	void solve() throws IOException {
		int n = nextInt();
		int k = nextToken().length();

		int[] noEmpty = goNoEmpty(n, k);
		int[] empty = goEmpty(n);
		
		int ret = 0;
		for (int i = 0; i <= n; i++) {
			ret += (int)((long)noEmpty[i] * empty[n - i] % P);
			ret %= P;
		}
		
		out.println(ret);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 16724
#include<cstdio>
#include<cstring>
char content[4][10]={"dream","dreamer","erase","eraser"};
char s[100005];
int main()
{
    scanf("%s",s);
    int n=strlen(s);
    bool flag;
    for(int i=0;i<n;i++)
    {
        flag=true;
        if(s[i]=='e')
        {
            int j;
            for(j=i;j<=i+4;j++)
            {
                if(s[j]!=content[2][j-i]||j>=n)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                if(s[j]=='r')
                    i=j;
                else
                    i=j-1;
            }
            else
            {
                printf("NO\n");
                return 0;
            }
        }
        else if(s[i]=='d')
        {
            int j;
            for(j=i;j<=i+4;j++)
            {
                if(s[j]!=content[0][j-i]||j>=n)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                if(s[j]=='e'&&s[j+1]=='r'&&s[j+2]!='a')
                    i=j+1;
                else
                    i=j-1;
            }
            else
            {
                printf("NO\n");
                return 0;
            }
        }
        else
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    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);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        long ans = 0;
        if(n >= 2){
            ans += (n * (n-1)) / 2;
        }
        if(m >= 2){
            ans += (m * (m-1)) / 2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll m;
    cin>>m;
    vector<ll>d(m),c(m);
    ll digit=0,sum=0;
    for(ll i=0;i<m;i++){
        cin>>d[i]>>c[i];
        digit+=c[i];
        sum+=d[i]*c[i];
    }
    cout<<(ll)(sum-1)/9+digit-1<<endl;
    return 0;
}


Measured memory_bytes: 3328
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	x := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
		sum += x[i]
	}

	avg := sum / n
	p := []int{avg - 1, avg, avg + 1}
	res := []int{0, 0, 0}

	for i := 0; i < n; i++ {
		for j := 0; j < len(p); j++ {
			res[j] += (x[i] - p[j]) * (x[i] - p[j])
		}
	}

	sort.Ints(res)
	fmt.Println(res[0])
}


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

int main() {
  int N,T,A;cin>>N>>T>>A;
  float m=9999999,n=0;
  for(int i=0; i<N; i++){
    int h;cin>>h;
    if(m>abs(A-(T-h*0.006))){
      m=abs(A-(T-h*0.006));n=i;
    }
  }
  cout<<n+1<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int L = arr[0] + arr[1];
    int r = arr[2] + arr[3];
    if (L > r) Console.WriteLine("Left");
    else if (L < r) Console.WriteLine("Right");
    else Console.WriteLine("Balanced");
  }
}

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

int main(){
    map<string,ll> a;
    set<string> l;
    int n;
    cin >> n;
    vector<string> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i++)
     sort(c[i].begin(),c[i].end());
    sort(c.begin(),c.end());
    ll ans = 0;
   for(int i = 0; i < n; i++){
       a[c[i]]++;
       l.insert(c[i]);
   }
    for(auto v : l){
        ans += a[v] * (a[v] - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 18176
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
#define M 1000000007

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll x;
    cin>>x;
    ll p=100,ans=0,l=10000;
    while(l--)
    {
        p=p + (p/100);
        ans++;
        //cout<<p<<" ";
        if(p>=x)
        {
          break;
        }
    }
    cout<<ans<<endl;
    
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
queue<char> Qa,Qb,Qc;

int main(){
    string sa,sb,sc;cin>>sa>>sb>>sc;
    for(int i=0;i<sa.size();i++)Qa.push(sa[i]);
    for(int i=0;i<sb.size();i++)Qb.push(sb[i]);
    for(int i=0;i<sc.size();i++)Qc.push(sc[i]);

    char flag='a',winner; 
    while(1){
        if(flag=='a'){
            if(Qa.empty()){
                cout<<'A'<<"\n"; break;
            }    
            flag=Qa.front(); Qa.pop();
        }
        else if(flag=='b'){
            if(Qb.empty()){
                cout<<'B'<<"\n";break;
            }    
            flag=Qb.front(); Qb.pop();
        }    
        else if(flag=='c'){
            if(Qc.empty()){
                cout<< 'C'<<"\n"; break;
            }    
            flag=Qc.front(); Qc.pop();
        }    
   }

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
#define MAX_N (int)1e7
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll b;
    while(cin >> b, b)
    {
        ll pos = 1, num = INF, ans1, ans2;
        while(1)
        {
            if(pos >= b) break;
            ll x = pos * (pos + 1) / 2;
            if(b < x) break;
            ll d = b - x;
            if(d % pos == 0)
            {
                ans1 = d / pos + 1;
                ans2 = pos;
            }
            pos++;
        }
        cout << ans1 << " " << ans2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
// Problem : C - Bugged
// Contest : AtCoder Regular Contest 075
// URL : https://atcoder.jp/contests/arc075/tasks/arc075_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, sum = 0, mn = inf, s[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
		if (s[i] % 10 != 0) {
			mn = min(mn, s[i]);
		}
		sum += s[i];
	}
	if (mn == inf) {
		cout << 0;
	} else if (sum % 10 != 0) {
		cout << sum;
	} else {
		cout << sum - mn;
	}
}


Measured memory_bytes: 256
N,K = map(int,input().split())
h = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

for i in range(N):
    for j in range(1, K + 1):
        if i>=j:
                dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])

print(dp[-1])

Measured memory_bytes: 55392
#include <iostream>
#include <math.h>
#include <vector>
#include <utility>
 
using namespace std;
 
bool DFSUtil(int, vector<bool>&, vector<bool> &);
vector<pair<int, long long>> g[1234567];
long long node[1234567] = {0};
int R, C;
long long minR, minC;
 
 
int main(){
  cin >> R >> C;
 
  for(int i = 0; i < C + R; i++){
    g[i].clear();
  }
 
  int N;
  cin >> N;  
  for(int i = 0; i < N; i++){
    int r, c;
    long long a;
    cin >> r >> c >> a;
    r--; c--;
    g[r].push_back(make_pair( c + R, a));
    g[c + R].push_back(make_pair(r, a));
  }
 
  vector<bool> visited(R + C, false);
  vector<bool> was(R + C, false);
  
  for(int i = 0; i < R + C; i++){
      was[i] = true;
      minR = 1000000000;
      minC = 1000000000;

      if(!DFSUtil(i, visited, was)){
        cout << "No";
        return 0;
      }
  }
  cout << "Yes";
}
 
bool DFSUtil(int v, vector<bool> &visited, vector<bool> &was){
  if(visited[v]) return true;
  visited[v] = true;
  for(int i = 0; i < g[v].size(); i++){
    int w = g[v][i].first;
    long long a = g[v][i].second;
    if(was[v] && was[w]){
      if(node[v] + node[w] != a){
        return false;
      }
      continue;
    }
    node[w] = a - node[v];
    was[w] = true;
 
    if(v < R) minR = minR >node[v] ? node[v] : minR;
    if(v >= R) minC = minC>node[v] ? node[v] : minC;
    if(w < R) minR = minR >node[w] ? node[w] : minR;
    if(w >= R) minC = minC>node[w] ? node[w] : minC;
 
    if(minR + minC < 0) return false;
    if(!visited[w]){
      if(!DFSUtil(w, visited, was)) return false;
    }
  }
  return true;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
const ll mod=1000000007;
const char nl='\n';

ll mp[1000010]={0};

void solve(){
    ll i,j,k,l,m,n,u,v,x,y;
    cin>>n;
    vector<ll> vc(n);
    ll gcd;
    cin>>gcd;
    mp[gcd]++;
    vc[0]=gcd;
    for(i=1;i<n;i++){
        cin>>vc[i];
        mp[vc[i]]++;
        gcd=__gcd(gcd,vc[i]);
    }
    if(gcd!=1){
        cout<<"not coprime"<<nl;
        return;
    }

    for(i=2;i<=1000000;i++){
        if(mp[i]>1){
            cout<<"setwise coprime"<<nl;
            return;
        }
    }

    for(i=0;i<n;i++){
        x=vc[i];
        for(j=2;j*j<x;j++){
            if(x%j==0){
                mp[j]++;
                mp[x/j]++;
                if(mp[j]>1 || mp[x/j]>1){
                    cout<<"setwise coprime"<<nl;
                    return;
                }
            }
        }
        if(j*j==x){
            mp[j]++;
            if(mp[j]>1 || mp[x/j]>1){
                cout<<"setwise coprime"<<nl;
                return;
            }
        }

    }
    cout<<"pairwise coprime"<<nl;


}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int t = 1,i=1;
//    cin >> t;
	while (t--)
	{
//	    cout<<"Case #"<< i++ <<": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 18732
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

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

    int ans = 1;
    rep(i,K){
        if(S[i] != '1'){
            ans = S[i]-'0';
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let n = scan!(sc; usize);
  sc.new_line();
  let mut a: Vec<i32> = sc.get_as_vec();
  println!("{}", a.iter().map(|v| v.to_string()).collect::<Vec<String>>().join(" "));
  for i in 1..n {
    let v = a[i];
    let mut j = (i - 1) as i32;
    while j >= 0 && a[j as usize] > v {
      a[(j + 1) as usize] = a[j as usize];
      j -= 1;
    }
    a[(j + 1) as usize] = v;
    println!("{}", a.iter().map(|v| v.to_string()).collect::<Vec<String>>().join(" "));
  }
}



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

int main() {
  ll N, D;
  cin >> N >> D;
  ll D2 = D * D;
  int ans = 0;
  rep(i, N) {
    ll X, Y;
    cin >> X >> Y;
    ll X2 = X * X;
    ll Y2 = Y * Y;
    if (X2 + Y2 <= D2) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();

		System.out.println(n < k ? x * n : x * k + y * (n - k));
	}

}

Measured memory_bytes: 35408
#include "bits/stdc++.h"
using namespace std;
#define ll long long
int main()
{
    ll x;
    cin >> x;
    map<int, int> m;
    for(int i = 1; i <= 6; i++)m[i] = 1;
    for(int i = 7; i <= 11; i++)m[i] = 2;
    if(x >= 1 && x <= 11)cout << m[x];
    else {
        ll divv = (x/11ll)*2ll;
        divv += m[x%11];
        cout << divv;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<stdio.h>

struct POINT{
	double x;
	double y;
};

struct VECTOR2{ // 2次元ベクトル
	double x;
	double y;
};

std::istream& operator >> ( std::istream& s , POINT& p )
{
	char c;
	return s >> p.x >> c >> p.y;
}

double getDotProduct( const VECTOR2& a , const VECTOR2& b )
{
	return a.x * b.x + a.y * b.y;
}

double getSizeofVECTOR2( const VECTOR2& a )
{
	return sqrt( pow( a.x , 2 ) + pow( a.y , 2 ) );
}

double getTheta( const VECTOR2& a , const VECTOR2& b )
{
	double dotProduct = getDotProduct( a , b );
	double sizeofVECTORa = getSizeofVECTOR2( a );
	double sizeofVECTORb = getSizeofVECTOR2( b );

	return acos( dotProduct / ( sizeofVECTORa * sizeofVECTORb ) );
}

int main(void)
{
	POINT p1, p2, q, r;
	while(1){
		char c;
		std::cin >> p1 >> c >> p2 >> c >> q;
		if( std::cin.eof() ){
			break;
		}
		VECTOR2 p1q, p1p2;
		p1q.x = q.x - p1.x;
		p1q.y = q.y - p1.y;
		p1p2.x = p2.x - p1.x;
		p1p2.y = p2.y - p1.y;
		POINT crossPoint;
		crossPoint.x = p1.x + p1p2.x * getDotProduct( p1q , p1p2 ) / pow(getSizeofVECTOR2(p1p2),2);
		crossPoint.y = p1.y + p1p2.y * getDotProduct( p1q , p1p2 ) / pow(getSizeofVECTOR2(p1p2),2);
		r.x = (crossPoint.x - q.x) + crossPoint.x;
		r.y = (crossPoint.y - q.y) + crossPoint.y;

		printf( "%f %f\n" , r.x , r.y );
	}

	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,t;
  cin >> n >> t;
  ll a[n],b[n];
  rep(i,n) cin >> a[i] >> b[i];
  ll ans=0;
  rrep(k,31) {
    if(!(t&(1LL<<k))) continue;
    ll s=1LL<<k;
    ll sum=0;
    rep(i,n) {
      bool f=1;
      REP(j,k,31) {
        if(!(t&(1LL<<j))&&(a[i]&(1LL<<j))) f=0;
      }
      if(!f) continue;
      if(!(a[i]&s)) sum+=b[i];
    }
    ans=max(ans,sum);
  }
  ll sum=0;
  rep(i,n) {
    bool f=1;
    rep(j,31) {
      if(!(t&(1LL<<j))&&(a[i]&(1LL<<j))) f=0;
    }
    if(f) sum+=b[i];
  }
  ans=max(ans,sum);
  pr(ans);
}

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


Measured memory_bytes: 1792
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::collections::HashMap;

fn main() {
    input! {
        w: chars
    }
    let mut table = HashMap::new();
    for ch in w {
        let c = table.entry(ch).or_insert(0);
        *c += 1;
    }
    let is_ok = table.values().all(|v| v % 2 == 0);
    println!("{}", if is_ok { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define lli long long int 
#define ll long long 
#define f(i, n) for(int i=0; i<n; i++)

using namespace std;




void test()
{
	string a, b;
	cin>>a>>b;
	int o=0;
	for(int i=0; i<a.size(); i++){
		if(a[i] != b[i]) o++;
	}
	cout<<o<<endl;
}

int main(){
	
	/*int t;
	cin>>t;
	
	while(t--){
		test();
	}*/
	
	test();
	return 0;

}







Measured memory_bytes: 3916
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;


int main(){
    string s, t;
    cin >> s >> t;
    const ll mod = s.size();
    vector<int> n[26];
    rep(i, s.size()){
        int num = s[i] - 'a';
        n[num].push_back(i);
    }
    rep(i, 26){
        if(n[i].size() == 0) continue;
        n[i].push_back(n[i][0] + mod);
    }
    ll ans = -1;
    rep(i, t.size()){
        if(n[t[i]-'a'].size() == 0){
            cout << "-1" << endl;
            return 0;
        }
        int num = t[i] - 'a';
        ll idx = ans % mod;
        auto itr = upper_bound(n[num].begin(), n[num].end(), idx);
        ans = (ans / mod) * mod + *itr;
        // cout << num << " " << *itr << endl;
        // cout << ans << endl;
    }
    // rep(i, 26){
    //     bool a = false;
    //     rep(j, n[i].size()){
    //         if(j == 0) cout << i + 1 << ";";
    //         cout << n[i][j] << " ";
    //         a = true;
    //     }
    //     if(a) cout << endl;
    // }
    cout << ans + 1 << endl;
}

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

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

vector<int>par(114514),rank(114514);

int root(int x){
        if(par[x]==x)return x;
        else root(par[x]);
}

void unite(int x,int y){
        x=root(x);
        y=root(y);
        if(rank[x]<rank[y])par[x]=y;
        else{
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
        }
}

bool same(int x,int y){
        return root(x)==root(y);
}

int main(){
        int n,q;
        cin>>n>>q;
        for(int i=0;i<n;i++){
                rank[i]=0;
                par[i]=i;
        }
        int com,x,y;
        for(int i=0;i<q;i++){
                cin>>com>>x>>y;
                if(com){
                        if(same(x,y))cout<<1<<endl;
                        else cout<<0<<endl;
                }else{
                        if(same(x,y))continue;
                        unite(x,y);
                }
        }
        return 0;
}


Measured memory_bytes: 3460
from math import sqrt
import heapq
# -*- coding: utf-8 *-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)


def calc_dist(s1, s2):
    dist = sqrt(sum([abs(a-b)**2 for a, b in zip(s1[:-1], s2[:-1])]))
    return max(dist-s1[3] - s2[3], 0)


def solve():
    N = int(input())
    if N == 0:
        exit()
    spheres = [list(map(float, input().split())) for _ in range(N)]
    dists = []
    Un = UnionFind(N)
    for i in range(N):
        for j in range(i+1, N):
            tmp = calc_dist(spheres[i], spheres[j])
            #dists.append([tmp, i, j])
            heapq.heappush(dists, [tmp, i, j])

    cost = 0
    #dists = sorted(dists, key=lambda x: x[0])
    for k in range(len(dists)):
        dist, i, j = heapq.heappop(dists)
        if Un.same(i, j):
            continue
        else:
            Un.union(i, j)
            cost += dist
    print("{:.3f}".format(cost))


while True:
    solve()



Measured memory_bytes: 6300
#include <bits/stdc++.h>
using namespace std;
int n,m,tmax,o,cnt,i,j,k,x[808],y[808],z[808],d[402][402],id[10100],dst[10100],p[10100];
vector<int> g[402],orders[10100];  // TODO: orders[i] can be just number, not vector
bool av[10100];
void init() {
  for (i=0; i<o; i++) p[i]=i;
  // TODO: some greedy?
}
void print_result() {
  int cur=0,pos=-1,ed=0,lst=-1;
  for (int i=0; i<o; i++) av[i]=false;
  for (int t=0; t<tmax; t++) {
    //if (t>75 && t<82) printf("time %d: pos %d %d\n",t,pos,ed);
    if (pos<0) {
      for (; cur<o && av[p[cur]] && pos==-dst[p[cur]]; cur++);
      if (cur>=o) {
        puts("-1");
        continue;
      }
      if (pos==-1) {
        for (int i=lst+1; i<=t; i++) for (int j=0; j<orders[i].size(); j++) {
          av[orders[i][j]]=true;
          //printf("%d is available\n",orders[i][j]);
        }
        lst=t;
      }
    }
    int ds=av[p[cur]]?dst[p[cur]]:1;
    //if (t>75 && t<82) printf("pcur=%d ds=%d\n",p[cur],ds);
    if (pos<0) {
      if (pos==-ds) {
        puts("-1");
        continue;
      }
      for (int i=0; i<g[-pos].size(); i++) {
        int e=g[-pos][i];
        int nxt=x[e]+y[e]+pos;
        //printf(" nxt=%d; %d =?= %d + %d\n",nxt,d[ds][-pos],d[ds][nxt],z[e]);
        if (d[ds][-pos]==d[ds][nxt]+z[e]) {
          printf("%d\n",nxt);
          if (z[e]>1) {
            ed=(x[e]==-pos)?1:(z[e]-1);
            pos=e;
          } else pos=-nxt;
          break;
        }
      }
    } else {
      if (d[ds][x[pos]]+ed<d[ds][y[pos]]+z[pos]-ed) {
        printf("%d\n",x[pos]);
        if (ed==1) pos=-x[pos]; else ed--;
      } else {
        printf("%d\n",y[pos]);
        if (ed+1==z[pos]) pos=-y[pos]; else ed++;
      }
    }
  }
}
int main() {
  scanf("%d%d",&n,&m);
  memset(d,10,sizeof(d));
  for (i=1; i<=n; i++) d[i][i]=0;
  for (i=1; i<=m; i++) {
    scanf("%d%d%d",&x[i],&y[i],&z[i]);
    d[x[i]][y[i]]=d[y[i]][x[i]]=z[i];
    g[x[i]].push_back(i);
    g[y[i]].push_back(i);
  }
  for (k=1; k<=n; k++) for (i=1; i<=n; i++) for (j=1; j<=n; j++)
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  //for (i=1; i<=n; i++, puts("")) for (j=1; j<=n; j++) printf("%d ",d[i][j]);
  scanf("%d",&tmax);
  for (i=0; i<tmax; i++) {
    scanf("%d",&cnt);
    for (j=0; j<cnt; j++, o++) {
      scanf("%d%d",&id[o],&dst[o]);
      orders[i].push_back(o);
    }
  }
  init();
  // TODO: fixed amount of rand_iterations + calc_score(best) + SA/HC
  print_result();
  return 0;
}


Measured memory_bytes: 1408
n = gets.chomp.to_i
d, x = gets.chomp.split(" ").map(&:to_i)
n.times do
  a = gets.chomp.to_i
  day = 1
  i = 1
  while true
    break if day > d
    x += 1
    day = i * a + 1
    i += 1
  end
end
puts x


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i,0,H) cin >> a[i];

  vector<bool> row(H, false);
  vector<bool> col(W, false);
  rep(i, 0, H) {
    rep(j, 0, W) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  rep(i, 0, H) {
    if (row[i]) {
      rep(j, 0, W) {
        if (col[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:k:as)=g(-1)$V.length bs where
  bs=V.fromList.sort.filter(<k)$as
  f j=V.or.V.slice(k-c)c.V.ifoldr(\i a v->if i==j then v else V.imap(\i b->b || (i>=a && v V.!(i-a)))v)(V.generate k(==0))$bs
    where c=bs V.! j
  g l r
    |l+1>=r=r
    |f m=g l m
    |otherwise=g m r
    where m=(l+r)`div`2

Measured memory_bytes: 8196
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

long long gcd(long long x, long long y){
    if(y == 0){
        return x;
    }
    return gcd(y, x%y);
}

int main(){
    long long a, b;

    cin >> a >> b;

    long long g = gcd(a, b);

    if(g == 1){
        printf("1\n");
        return 0;
    }

    long long num = g;
    long long count = 1;

    //long long pivot = (long long)sqrt(g);
    for(long long i = 2; i*i <= g+1; i++){
        if(num % i != 0){
            continue;
        }

        bool first = true;
        while(num % i == 0){
            if(first == true){
                count++;
            }
            first = false;
            num /= i;
        }
    }
    if(num != 1){
        count++;
    }

    cout << count << endl;

    return 0;

}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;

  for (int i = 0; i <= n - 3; i++){
      if(s.substr(i, 3) == "ABC") ans++;
  }

  cout << ans << endl;
}



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

int main(){
    int A, B, C; cin >> A >> B >> C;

    if(A + B >= C-1){
        cout << B + C << endl;
    }

    else{
        cout << A + 2*B + 1 << endl;
    }
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] datas = new int[Integer.parseInt(reader.readLine())];
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    long sum = 0;
    int c = 0;
    for (String str : reader.readLine().split(" ")) {
      datas[c] = Integer.parseInt(str);
      c++;
    }
    for (int data : datas) {
      if (min > data)
        min = data;
      if (max < data)
        max = data;
      sum += data;
    }
    System.out.println(String.format("%d %d %d", min, max, sum));
  }

}

Measured memory_bytes: 25572
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int H, W, D; cin >> H >> W >> D;
    vector<pair<int, int>> rowColPairs(H * W);
    for (int r = 1; r <= H; ++r)
    {
        for (int c = 1; c <= W; ++c)
        {
            int Arc; cin >> Arc;
            rowColPairs[Arc - 1] = { r, c };
        }
    }
    // Dを法とする各集合に対して，必要な魔力を累積和で管理
    // 計算量は累積和計算＋クエリでO(HW+Q)~O(10^5)
    vector<vector<LLONG>> cumSums(D, vector<LLONG>((H * W + D - 1) / D));
    // 1~Dは必要魔力ゼロ
    for (int i = 1; i <= D; ++i)
    {
        cumSums[i % D][0] = 0;
    }
    // 累積和の計算：O(HW)
    for (int i = D + 1; i <= H * W; ++i)
    {
        int x = (i - 1) / D;
        const auto prevPos = rowColPairs[i - D - 1];
        const auto curPos = rowColPairs[i - 1];
        cumSums[i % D][x] = cumSums[i % D][x - 1]
            + abs(prevPos.first - curPos.first)
            + abs(prevPos.second - curPos.second);
    }
    // クエリに答える：O(Q)
    int Q; cin >> Q;
    for (int i = 0; i < Q; ++i)
    {
        int Li, Ri; cin >> Li >> Ri;
        cout << cumSums[Li % D][(Ri - 1) / D]
            - cumSums[Li % D][(Li - 1) / D] << endl;
    }

    //int Q; cin >> Q;
    //// O(QHW)なので時間が足りない…？
    //for (int i = 0; i < Q; ++i)
    //{
    //    int Li, Ri; cin >> Li >> Ri;
    //    LLONG ans = 0;
    //    // O(HW)
    //    for (int x = Li; x < Ri; x += D)
    //    {
    //        const auto curPos = rowColPairs[x - 1];
    //        const auto nextPos = rowColPairs[x + D - 1];
    //        ans += abs(curPos.first - nextPos.first)
    //            + abs(curPos.second - nextPos.second);
    //    }
    //    cout << ans << endl;
    //}
}

Measured memory_bytes: 6016
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)1e9+1
#define MOD (long long)1e9+7
#define INF64 (long long)1e18+1

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  llint A,B;
  cin >> A >> B;

  //SOLVE
  llint ans=0;
  llint buf;
  buf = 1;
  rep(i,0,100) {
    if (buf >= B) {
      break;
    } else {
      buf += A-1;
      ans++;
    }

  }

  //OUTPUT
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

// 1-indexed 2d BIT
class BIT2{
    public:
    ll H, W;
    vector<vector<ll> >bit;
    BIT2(ll _H, ll _W){
        H = _H + 5;
        W = _W + 5;
        bit.resize(_H + 10, vector<ll>(_W + 10, 0));
    }
    void add_point(ll x, ll y, ll v){
        for(ll Y = y; Y <= H; Y += Y & -Y){
            for(ll X = x; X <= W; X += X & -X){        
                bit[Y][X] += v;
            }
        }
    }
    ll get_sum(ll x, ll y){
        if(x <= 0 || y <= 0)return 0;
        if(x > W || y > H)return 0;
        ll sum = 0;
        for(ll Y = y; Y > 0; Y -= Y & -Y){
            for(ll X = x; X > 0; X -= X & -X){
                sum += bit[Y][X];
            }
        }
        return sum;
    }
    ll get_sum(ll x1, ll y1, ll x2, ll y2){
        ll tmp = 0;
        tmp += get_sum(x2, y2);
        tmp -= get_sum(x2, y1 - 1);
        tmp -= get_sum(x1 - 1, y2);
        tmp += get_sum(x1 - 1, y1 - 1);
        return tmp;
    }
};

int main(){

    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0){
        cout << "No" << endl;
        return 0;
    }
    BIT2 bit(H, W);
    ll a = 999999999 / (h * w - 1);
    ll total = a * H * W;
    rep1(y, H)rep1(x, W){
        bit.add_point(x, y, a);
    }
    rep1(y1, H + 1 - h)rep1(x1, W + 1 - w){
        ll x2 = x1 + w - 1;
        ll y2 = y1 + h - 1;
        ll sum = bit.get_sum(x1, y1, x2, y2);
        if(sum < 0)continue;
        bit.add_point(x2, y2, - (sum + 1));
        total -= (sum + 1);
    }
    if(total <= 0){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    rep1(y, H){
        rep1(x, W){
            cout << bit.get_sum(x, y, x, y);
            if(x == W)cout << endl;
            else cout << " ";
        }
    }
    return 0;
}

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


using namespace std;
#define out(s) cout<<(s)<<endl;
using ll = long long;

int main()
{
	string S;
	cin >> S;
	int P = 0;
	for (auto c : S) {
		if (c == 'p') P++;
	}
	out(S.size() / 2 - P);
	return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector< vector<int> > g(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;

    vector< vector<int> > d(n, vector<int>(3, -1));
    queue<P> q;
    q.emplace(s, 0);
    d[s][0] = 0;
    while (!q.empty()) {
        P p = q.front();
        q.pop();
        if (p.first == t && p.second == 0) break;
        int hoge = (p.second + 1) % 3;
        for (int nex : g[p.first]) {
            if (d[nex][hoge] != -1) continue;
            d[nex][hoge] = d[p.first][p.second] + (p.second == 0);
            q.emplace(nex, hoge);
        }
    }
    cout << d[t][0] << endl;
    return 0;
}

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

using namespace std;

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

	int a, b, ans = 0;

	cin >> a >> b;

	if (a >= 13) ans = b;
	if (a >= 6 && a <= 12) ans = b/2;

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

from collections import deque
import heapq
INF = 10**18

def dijkstra(start, G):
    done = [False]*(len(G))
    dist = [INF]*(len(G))
    dist[start] = 0
    h = []
    heapq.heappush(h, [0, start])
    while h:
        _, cur = heapq.heappop(h)
        if done[cur]: continue
        done[cur] = True
        for to, cost in G[cur]:
            if dist[cur]+cost < dist[to]:
                dist[to] = dist[cur]+cost
                heapq.heappush(h, [dist[to], to])
    return dist

H, W = map(int, input().split())
sh, sw = map(lambda x: int(x)-1, input().split())
gh, gw = map(lambda x: int(x)-1, input().split())
S = [input() for _ in range(H)]
done = [[-1]*W for _ in range(H)]
q = deque()
num = 0
for ii in range(H):
    for jj in range(W):
        if done[ii][jj] != -1: continue
        q.append((ii, jj))
        done[ii][jj] = num
        while q:
            h, w = q.popleft()
            for dh, dw in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
                nh, nw = h+dh, w+dw
                if not (0 <= nh < H and 0 <= nw < W and S[nh][nw] == "."):
                    continue
                if done[nh][nw] == -1:
                    q.append((nh, nw))
                    done[nh][nw] = num
        num += 1
G = [[] for _ in range(num)]
done2 = {}
for h in range(H):
    for w in range(W):
        if S[h][w] != ".": continue
        fr = done[h][w]
        for ii in range(-2, 3):
            for jj in range(-2, 3):
                nh, nw = h+ii, w+jj
                if not (0 <= nh < H and 0 <= nw < W and S[nh][nw] == "."):
                    continue
                to = done[nh][nw]
                if fr != to and (not (fr, to) in done2):
                    done2[(fr, to)] = True
                    done2[(to, fr)] = True
                    G[fr].append((to, 1))
                    G[to].append((fr, 1))
D = dijkstra(done[sh][sw], G)
ans = D[done[gh][gw]]
if ans != INF:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 213344
import java.util.*;

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

        int X = sc.nextInt();
        int A = sc.nextInt();

        if(X<A){
            System.out.println(0);
        }
        else if(X>=A){
            System.out.println(10);
        }
    }
}

Measured memory_bytes: 22612
program main
character::S*4
integer::i,check
read*,S
check=0
do i=1,3
	if(S(i:i)==S(i+1:i+1))then
    	check=check+1
    else
    	check=check
    end if
end do
if(check==0)then
print*,'Good'
else
print*,'Bad'
end if
end program main

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

#include <bits/stdc++.h>

using namespace std;

struct Edge {int to, cost; };
typedef pair<int, int> pint;

#define INF (1000 * 1000 * 1000)

class Dikstra {
private:
    int N;
    vector<vector<Edge>> edge_list;

public:
    Dikstra(vector< vector<Edge>> &edge_list) {
        this->edge_list = edge_list;
        this->N = edge_list.size();
    }

    vector<int> search(int s) {
        priority_queue<pint, vector<pint>, greater<pint> > que;
        vector<int> d(N, INF);
        d[s] = 0;
        que.push(make_pair(0, s));

        while (!que.empty()) {
            pint p = que.top();
            que.pop();

            int v = p.second;
            if (d[v] < p.first) continue;

            for (Edge e: edge_list[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }

        return d;
    }
};

int idx(int i, int s, int N) {
    return (i + s * N) % (3 * N);
}

signed main() {
    int N, M;
    cin >> N >> M;

    vector< vector< Edge>> edges(N*3, vector<Edge> ());

    REP (i, M) {
        int u, v;
        cin >> u >> v;
        u--; v--;

        edges[idx(u, 0, N)].pb(Edge{idx(v, 1, N), 1});
        edges[idx(u, 1, N)].pb(Edge{idx(v, 2, N), 1});
        edges[idx(u, 2, N)].pb(Edge{idx(v, 0, N), 1});
    }

    int S, T;
    cin >> S >> T;
    S--; T--;

    Dikstra dks(edges);
    vector<int> distance = dks.search(idx(S, 0, N));

    if (distance[idx(T, 0, N)] == INF) {
        cout << -1 << endl;
    } else {
        cout << distance[idx(T, 0, N)] / 3 << endl;
    }

    return 0;
}

Measured memory_bytes: 34176
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

# sys.setrecursionlimit(10**6)
def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def get_string(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
n = int(input())
print(math.ceil(n/1000)*1000-n)

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 67476
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define MAX 100000
using namespace std;
ll L = 1000000007;
int cnt[100010] = {};
int main()
{	
	int n;
	ll ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a > 100000) {
			ans++;
		}
		else {
			cnt[a]++;
		}
	}

	for (int i = 1; i <= 100000; i++)
	{
		if (i == cnt[i] || cnt[i] == 0) {
			continue;
		}
		else if(cnt[i] < i) {
			ans += cnt[i];
		}
		else if(i < cnt[i]){
			ans += cnt[i] - i;
		}
	}
	
	cout << ans << endl;
	return 0;
	

}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


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

#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<int,pi>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define debug cout<<"debugging"<<endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int I_LIMIT = 999999999;
ll L_LIMIT = 1999999999999999999;
ll mod = 1000000007;
vector <int> v[100005];

void solve()
{
    ll n,p,k,ans=0,i,p1;
    cin>>n;

    k=1;
    for(i=1;i<=n;i++)
        k = (k*10)%mod;
    
    p=1;
    for(i=1;i<=n;i++)
        p = (p*9)%mod;
    p = (p*2)%mod;

    p1=1;
    for(i=1;i<=n;i++)
        p1 = (p1*8)%mod;

    ans = (k-p+p1+mod*mod)%mod;
    cout<<ans<<"\n";
}
int main()
{
    IOS;
    int t;
    //cin>>t;
    //for(int i=1;i<=t;i++)
        solve();
}


Measured memory_bytes: 5976