akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

class LowLink:
    def __init__(self, v):
        self.size = len(v)
        self.v = v
        self.pre = [None]*self.size
        self.low = [None]*self.size
        self.articulation = []
        self.bridge = []
        for x in range(self.size):
            if self.pre[x] is None:
                self.cnt = 0
                self.dfs(x,None)

    def dfs(self, x, par):
        self.pre[x] = self.low[x] = self.cnt
        self.cnt += 1
        is_articulation = False
        n = 0
        for y in self.v[x]:
            if self.pre[y] is None:
                n += 1
                lowy = self.dfs(y, x)
                if lowy < self.low[x]:
                    self.low[x] = lowy
                if self.pre[x] <= lowy:
                    if self.pre[x]:
                        is_articulation = True
                    if self.pre[x] < lowy:
                        self.bridge.append((x,y))
            else:
                if par != y and self.pre[y] < self.low[x]:
                    self.low[x] = self.pre[y]

        if par is None and n > 1:
            is_articulation = True

        if is_articulation:
            self.articulation.append(x)

        return self.low[x]


def solve():
    n,m = LI()
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        v[a].append(b)
        v[b].append(a)
    lowlink = LowLink(v)
    bridge = lowlink.bridge
    for i in range(len(bridge)):
        l,r = bridge[i]
        if r < l:
            bridge[i] = (r,l)
    for i in sorted(bridge):
        print(*i)
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 19764
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *min=(int *)malloc(sizeof(int)*(n+1));
  int i,j;
  for(i=0;i<=n;i++) min[i]=i;
  for(i=6;i<=n;i*=6){
    for(j=i;j<=n;j++){
      min[j]=MIN(min[j],min[j-i]+1);
    }
  }
  for(i=9;i<=n;i*=9){
    for(j=i;j<=n;j++){
      min[j]=MIN(min[j],min[j-i]+1);
    }
  }
  printf("%d\n",min[n]);
  return;
}

int main(void){
  run();
  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> x(n),y(n);
    ll ans=4*1e18;
    for(int i = 0;i < n;i ++){
        cin >> x[i] >> y[i];
    }
    for(int xi = 0;xi < n;xi ++){
        for(int xj = xi+1;xj < n;xj ++){
            for(int yi = 0;yi < n;yi ++){
                for(int yj = yi+1;yj < n;yj ++){
                    ll lx=x[xi],rx=x[xj],uy=y[yi],dy=y[yj];
                    if(lx>rx) swap(lx,rx);
                    if(uy<dy) swap(uy,dy);
                    ll cnt = 0;
                    for(int i = 0;i < n;i ++){
                        if(lx<=x[i]&&x[i]<=rx&&dy<=y[i]&&y[i]<=uy) cnt ++;
                    }
                    if(cnt>=k) ans = min(ans,(rx-lx)*(uy-dy));
                }
            }
        }
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,k,a[100010];
int np[60];
int dbs[60];
ll dp[2][60],qp[2][60];
ll r=0,qr=0;

const int ti=60;

ll pow(int target,int repeat){
    ll result=1;
    for(int i=0;i<repeat;i++)result*=target;
    return result;
}

int main(){
    
    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        ll bc=a[i];
        for(int j=0;j<ti;j++){
            np[j]+=bc%2;
            bc=bc>>1;
        }
    }
    
    for(int i=ti-1;i>=0;i--){
        dbs[i]=(n-np[i]>=np[i] and r+pow(2,i)<=k);
        if(dbs[i])r+=pow(2,i);
        
    }
    for(int i=0;i<n;i++){
        qr+=a[i] xor r;
    }
    printf("%lld\n",qr);
    

    /*
    for(int i=0;i<10;i++){
        cout<<c%2<<endl;
        c=c>>1;
    }
    
    */
    
    
    
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(void) {
	signed long long a;
	signed long long b;
	signed long long c;
	signed long long d;
	signed long long ac;
	signed long long ad;
	signed long long bc;
	signed long long bd;
	signed long long output;

	scanf("%lld %lld %lld %lld", &a, &b , &c, &d);
	ac = a * c;
	ad = a * d;
	bc = b * c;
	bd = b * d;

	if (ac > ad) {
		output = ac;
	}
	else {
		output = ad;
	}
	if (output < bc) {
		output = bc;
	}
	if (output < bd) {
		output = bd;
	}

	printf("%lld",output);

	return 0;
}

Measured memory_bytes: 1732
n = int(input())
aList = list(map(int, input().split()))
flag = True
for i in aList:
    if i % 2 == 0 and i % 3 != 0 and i % 5 != 0:
        flag = False
        break
if flag:
    print("APPROVED")
else:
    print("DENIED")

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

int main(){
  string S;
  cin >> S;
  int i=1,ans=1;
  while(i<S.size()){
    if(i<S.size()-2){
    if(S[i]!=S[i-1]){
      ans++;
      i++;
    }
    else{
      ans+=2;
      i+=3;
    }
    }
      else if(i==S.size()-2){
        if(S[S.size()-3]==S[S.size()-2]){
          ans++;
          i+=2;
        }
        else{
          ans++;
          i++;
        }
      }
    else{
      if(S[S.size()-1]==S[S.size()-2]){
        i++;
      }
      else{
        ans++;
        i++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    static final int hashA = 97;
    static final int hashPeriod = 46;
    void run() throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String[] alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
        int[] cntAlpha = new int[alphabet.length];
        String txt = br.readLine();
        while( txt != null && ! "".equals(txt) ){
            for (int i = 0;i < txt.length();i++){
                txt = txt.toLowerCase();
                char ch = txt.charAt(i);
                int hash = String.valueOf(ch).hashCode();
                if(hash >= hashA && hash < hashA + alphabet.length){
                    cntAlpha[hash - hashA]++;
                }
            }
            txt = br.readLine();
        }
        for(int i = 0;i < alphabet.length;i++){
            System.out.println(alphabet[i] + " : " + cntAlpha[i]);
        }
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}

Measured memory_bytes: 26252
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

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

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	vector<vector<int>>s(100030);
	map<pair<int,int>,int>k;
	int n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int u,v,w;
		cin >> u>>v>>w;
		s[u].push_back(v);
		s[v].push_back(u);
		pair<int, int> q;
		q.first = u;
		q.second = v;
		k[q] = w;

	}
	int seen[100030] = {};
	seen[1] = 1;
	queue<int> qq;
	qq.push(1);
	while (qq.size()) {
		int t = qq.front();
		qq.pop();
		for (auto i : s[t]) {
			if (seen[i] == 0) {
				qq.push(i);
				pair<int, int>x;
				x.first = t;
				x.second = i;
				int tl = 0;

				if (k[x] == 0) {
					x.first = i;
					x.second = t;
					tl = k[x];
				}
				else {
					tl = k[x];
				}

				if (tl % 2 == 0) {
					seen[i] = seen[t];
				}
				else {
					if (seen[t] == 2) {
						seen[i] = 1;
					}
					else {
						seen[i] = 2;
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if (seen[i] == 1) {
			cout << 0 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
}

Measured memory_bytes: 15744
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String input=scanner.nextLine();
		int cnt=0;
		for(int i=0;i<3;i++){
			if(input.charAt(i)=='1'){
				cnt++;
			}
		}
		System.out.println(cnt);
		scanner.close();
	}
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double r = sc.nextDouble();
    double pi = Math.PI;
    double area = r*r*pi;
    double length = 2*r*pi;
    System.out.printf("%f %f\n", area, length);
  }
}



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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	int hlist[446];
	int pos = -1;
	for (int i = 0;i < 446;i++) {
		hlist[i] = ((i+1)*(i+2))/2;
		if (n == hlist[i]) {
			pos = i + 2;
		}
	}
	if (pos == -1) {
		cout << "No" << endl;
	} else {
		vector<int> ans[pos];
		int count = 1;
		for (int i = 0;i < pos;i++) {
			for (int j = i + 1;j < pos;j++) {
				ans[i].push_back(count);
				ans[j].push_back(count);
				count++;
			}
		}
		cout << "Yes" << endl;
		cout << pos << endl;
		for (int i = 0;i < pos;i++) {
			cout << pos-1 << " ";
			for (int j = 0;j < pos-1;j++) {
				cout << ans[i].at(j) << " ";
			}
			cout << endl;
		}
	}
}

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

using namespace std;
int main() {
  string cards;
  int n;
  while(cin >> cards) {
    if (cards == "-") {
      return 0;
    }
    cin >> n;
    for(int i=0; i<n; i++) {
      int h;
      cin >> h;

      string str="";
      for(int j=0; j<h; j++) {
        str += cards[j];
      }

      for(unsigned int j=0; j < cards.length()-h; j++) {
        cards[j] = cards[j+h];
      }
      int pos=0;
      for(int j=h; 0<j; j--) {
        cards[cards.length()-j] = str[pos];
        pos++;
      }
    }
    cout << cards << endl;
  }
}

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

int islands=0;
int w,h;
int field[50][50];
void bfs(int, int);

int main(){

  while(cin>>w>>h&&w!=0&&h!=0){

    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++){
        field[i][j] = -1;
      }
    }

    for(int j=0;j<h;j++){
      for(int i=0;i<w;i++){
        cin >> field[i][j];
        //        cout << field[i][j] << " ";
      }
      //    cout << endl;
    }
    // cout << endl;
    int ans=0; 

    for(int j=0;j<h;j++){
      for(int i=0;i<w;i++){
        if(field[i][j]==1){
          field[i][j]=0;
          bfs(i,j);
          ans++;
        }
      }
    }
    /*   if(w==5&&h==4){
         for(int i=0;i<w;i++){
         for(int j=0;j<h;j++){
         cout << field[i][j] << " ";
         }
         cout << endl;
         }
         }*/
    cout << ans << endl;
  }

  return 0;
}

void bfs(int x, int y){
  if(x-1>=0&&field[x-1][y]==1){
    field[x-1][y]=0;
    bfs(x-1,y);
  }
  if(x+1<w&&field[x+1][y]==1){
    field[x+1][y]=0;
    bfs(x+1,y);
  }
  if(y-1>=0&&field[x][y-1]==1){
    field[x][y-1]=0;
    bfs(x,y-1);
  }
  if(y+1<h&&field[x][y+1]==1){
    field[x][y+1]=0;
    bfs(x, y+1);
  }
  if(x-1>=0&&y-1>=0&&field[x-1][y-1]==1){
    field[x-1][y-1]=0;
    bfs(x-1,y-1);
  }
  if(x+1<w&&y-1>=0&&field[x+1][y-1]==1){
    field[x+1][y-1]=0;
    bfs(x+1,y-1);
  }
  if(x-1>=0&&y+1<h&&field[x-1][y+1]==1){
    field[x-1][y+1]=0;
    bfs(x-1,y+1);
  }
  if(x+1<w&&y+1<h&&field[x+1][y+1]==1){
    field[x+1][y+1]=0;
    bfs(x+1,y+1);
  }
  return;
}

Measured memory_bytes: 1348
#include <stdio.h>



void Print(int i, int a)
{
	switch (i) {
	case 0:
		printf("pre-meiji\n");
		break;
	case 1:
		printf("meiji %d %d %d\n", a / 10000 - 1867, (a % 10000) / 100, (a % 100));
		break;
	case 2:
		printf("taisho %d %d %d\n", a / 10000 - 1911, (a % 10000) / 100, (a % 100));
		break;
	case 3:
		printf("showa %d %d %d\n", a / 10000 - 1925, (a % 10000) / 100, (a % 100));
		break;
	case 4:
		printf("heisei %d %d %d\n", a / 10000 - 1988, (a % 10000) / 100, (a % 100));
		break;
	}
}


int main(void)
{
	int iy, im, id;
	int kami;

	int meiji = 1868 * 10000 + 9 * 100 + 8;
	int taisho = 1912 * 10000 + 7 * 100 + 30;
	int showa = 1926 * 10000 + 12 * 100 + 25;
	int heisei = 1989 * 10000 + 1 * 100 + 8;

	while (1) {
		if (scanf("%d %d %d", &iy, &im, &id) == EOF) {
			break;
		}

		kami = iy * 10000 + im * 100 + id;

		if (kami<meiji) {
			Print(0, kami);
		} else if (kami >= meiji && kami<taisho) {
			Print(1, kami);
		} else if (kami >= taisho && kami<showa) {
			Print(2, kami);
		} else if (kami >= showa && kami<heisei) {
			Print(3, kami);
		} else {
			Print(4, kami);
		}
	}

	return 0;
}

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

int main(){
    int N; cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];

    vector<unordered_map<int,int>> MP(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < S[i].size(); j++){
            MP[i][S[i][j]]++;
        }
    }
    int cnt[26] = {0};
    memset(cnt, 50, sizeof(cnt));
    for(char c = 'a' ; c <= 'z' ; c++){
        for(int i = 0; i < N; i++){
            cnt[c - 'a'] = min(MP[i][c], cnt[c-'a']);
        }
    }
    for(int i = 0; i < 26; i++){
        while(cnt[i] > 0){
            cout << (char)('a' + i);
            cnt[i]--;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const int MOD = 1000000007;

int f(ll a[], ll n, ll k, vll &vis, ll count, ll now) {
	/* deb(count);deb(k);deb(now);deb(vis[now]); */
	if(count == k+1)
		return now+1;
	if(vis[now] == 0) {
		vis[now] = count;
		count++;
		ll ans = f(a, n, k, vis, count, a[now]-1);
		return ans;
	}
	else {
		ll m = count - vis[now];
		/* deb(m);deb(count);deb(k);deb(now); */
		if(m > k-count)
			k = m-(k-count);
		else
			k = (k-count)%m+1;
		/* deb(k); */
		for(ll i=1;i<=k;i++)
			now = a[now]-1;
		return now+1;
	}
}

int main() {
	fastio();
	ll n;ll k;
	cin >> n >> k;
	ll a[n];
	for(ll i=0;i<n;i++)
		cin >> a[i];
	vll vis(n, 0);
	ll count = 1;
	cout << f(a, n, k, vis, count, 0) << "\n";
	return 0;
}


Measured memory_bytes: 6360
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using iii = pair<int, ii>;
using viii = vector<iii>;

using ll = long long int;
using vc = vector<char>;
using vb = vector<bool>;
using ib = pair<int, bool>;
using vib = vector<ib>;

#define MOD 1000 * 1000 * 1000 + 7
#define INF 1000 * 1000 * 1000
#define EMPTY -10
#define mp(a, b) make_pair(a,b)

bool resuelveCaso() {
	int n;
	cin >> n;
	if (!cin) return false;
	int m, x, y;
	cin >> m >> x >> y;

	vi v1(n);
	vi v2(m);

	for (int i = 0; i < n; ++i) cin >> v1[i];
	for (int i = 0; i < m; ++i) cin >> v2[i];

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());

	if (min(v2[0], y) > max(v1[n - 1], x)) cout << "No War\n";
	else cout << "War\n";

	return true;
}

int main() {
	while (resuelveCaso()) {}
	return 0;
}

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

#define ll long long
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll x;
	cin >> x;
	
	ll a, b, i, j;
	bool flag = 0;
	for (i = -1000; i <= 1000; i++) {
		a = i*i*i*i*i;
		for (j = -1000; j <= 1000; j++) {
			b = j*j*j*j*j;
			if (a-b==x) {assert(a-b==x);flag=1;break;}
		}
		if (flag) break;
	}

	cout << i << " " << j << "\n";
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include<cmath>
#include<cstring>
#define pb push_back
#define pi acos(-1.0)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define rloop(i,a,n) for(int i=n;i>=a;i--)
#define ff first
#define ss second
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(gcd(a,b))
#define ms(a,b) memset(a,b,sizeof a)
#define check cout<<"HI"<<endl;

using namespace std;


#define i64 unsigned long long

long long int dp[9999][9999];

void nCr()
{
    dp[0][0]=1;
    loop(i,1,2011)
    {
        loop(j,1,i+1)
        {
            dp[i][0]=1;
            if(i==j)dp[i][j]=1;
            else
            {
                dp[i][j]=(dp[i-1][j-1]%1000000007 + dp[i-1][j]%1000000007)%1000000007;
            }
        }
    }
}

int main()
{
    nCr();
    int n ,k,m ;
    sc2(n,k);
    m=n-k+1;
    cout<<m<<endl;
    loop(i,2,k+1){
        long long int ans = (dp[m][i]%1000000007*dp[k-1][i-1]%1000000007)%1000000007;
    //long long int ans = (nCr(m, i)%1000000009*nCr((k-1),(i-1))%1000000007)%1000000009;
    printf("%lld\n",ans);
    }//cout <<nCrModp(m, k, 1000000007)<<endl;

    return 0;
}
;









Measured memory_bytes: 156032
#include<cstdio>
using namespace std;
template<class T>inline void read(T&a){
	char c=getchar();int f=1;a=0;
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0') a=(a<<1)+(a<<3)+c-48,c=getchar();
	a*=f;
}
template<class T>void write(T a){
	if(a<0) putchar('-'),a=-a;
	if(a>9) write(a/10);
	putchar(a%10+48);
}
char s[4];
int main(){
	scanf("%s",s+1);
	putchar((s[1]=='R'&&s[2]=='R'&&s[3]=='R')?51:(s[2]=='R'&&(s[1]=='R'||s[3]=='R'))?50:(s[1]=='R'||s[2]=='R'||s[3]=='R')?49:48);
	return 0;
}

Measured memory_bytes: 1664
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    H, W = read_ints()
    Ch, Cw = read_ints()
    Ch -= 1
    Cw -= 1
    Dh, Dw = read_ints()
    Dh -= 1
    Dw -= 1
    table = []
    for _ in range(H):
        table.append(list(input()))
    costs = [
        [math.inf for _ in range(W)] for _ in range(H)
    ]

    def dfs(points, cost):
        Q = list(points)
        discovered = list(points)
        while Q:
            i, j = Q.pop()
            for x, y in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
                if 0 <= x < H and 0 <= y < W and table[x][y] == '.' and costs[x][y] == math.inf:
                    costs[x][y] = cost
                    Q.append((x, y))
                    discovered.append((x, y))
        reachables = []
        for x, y in discovered:
            for dx in range(-2, 3):
                for dy in range(-2, 3):
                    new_x, new_y = x+dx, y+dy
                    if 0 <= new_x < H and 0 <= new_y < W and table[new_x][new_y] == '.' and costs[new_x][new_y] == math.inf:
                        costs[new_x][new_y] = cost+1
                        reachables.append((new_x, new_y))
        return reachables

    cost = 0
    Q = [(Ch, Cw)]
    costs[Ch][Cw] = 0
    while Q:
        Q = dfs(Q, cost)
        cost += 1
    if costs[Dh][Dw] == math.inf:
        return -1
    return costs[Dh][Dw]


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


Measured memory_bytes: 145416
import java.util.*;


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

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
		String str = sc.next();
        
        String[] word = str.split("");
        
        int count = 1;
        String current = word[0];
        
        for(int i = 1; i < N; i++){
            if(word[i].equals(current)){
                continue;
            }else{
                count++;
                current = word[i];
            }
        }
      	System.out.println(count);
    }
}

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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

  mint ans = 0;
  mint p = 1;
  mint q = 1;
  rep(i, min(n , k + 1)){
    ans += p * q;
    p = p * (n - 1 - i) / (i + 1);
    q = q * (n - i) / (i + 1);
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

ll n;
ll a[400];

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

    cin >> n;
    rep(i, n) cin >> a[i];

    ll y = 0;
    FOR(i, 2, n) y ^= a[i];

    ll x = a[0] + a[1];

    int xx[70]{}, yy[70]{};

    rep(i, 60) {
        xx[i] = x >> i & 1;
        yy[i] = y >> i & 1;
    }

    for(int i = 60; i >= 0; i--) {
        if(xx[i] % 2 != yy[i]) {
            if(!i) {
                cout << -1 << endl;
                return 0;
            }
            xx[i]--;
            xx[i - 1] += 2;
        }
        if(xx[i] < 0) {
            cout << -1 << endl;
            return 0;
        }
        if(xx[i] >= 3) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll z = 0;

    FORR(i, 60)
    if(xx[i] == 2) z += 1LL << i;

    FORR(i, 60)
    if(xx[i] == 1 && z + (1LL << i) <= a[0]) z += 1LL << i;

    if(z == 0 || z > a[0]) {
        cout << -1 << endl;
        return 0;
    }

    cout << a[0] - z << endl;

    return 0;
}

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

ll gcd(long a, long b){
    long ans = 1;
    long n = max(a,b);
    for(int i = 1; i <= n/2 ; i++){
        if(a%i==0&&b%i == 0){
            ans = i;
        }
    }
    return ans;
}

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

    cout << a*b/gcd(a,b) << endl;
   
    return 0;
    
}


Measured memory_bytes: 256
a, b, c = gets.chomp.split(" ").map(&:to_i)
K = gets.to_i
t = 0
u = 0
if a >= b
 t = a
 u = a
  if  c >= a
 t = c
 u = c
  end
else
 t = b
 u = b
  if c >= b
 t = c
 u = c
  end
end
for i in 1..K
 t = t * 2
end
puts "#{a+b+c+t-u}"

Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
string str;
bool bad = false;
int main(){
  cin >> str;
  for(int i = 0; i < 3; ++i){
    if(str[i]==str[i+1]){
      bad = true;
    } 
  }
if(bad==true){
      cout << "Bad" << endl;
}else{
      cout << "Good" << endl;
}
}

  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

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

    bool f = false;
    if (S.size() % 2 == 0) {
        f = true;
        REP(i, S.size()) {
            if (S[i] != (i % 2 ? 'i' : 'h')) f = false;
        }
    }

    cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int k = sc.nextInt();
		
		int ans = n % k;
		
		
		
		if (ans == 0){
			System.out.println(0);
		}
		else {
			System.out.println(1);
		}
	}
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//僕と契約して魔法少女になってよ！

int main(){
  int H,W,D;
  cin>>H>>W>>D;
  vector<pair<ll,ll>> T(90001);
  int x;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>x;
      T[x]={i,j};
    }
  }
  vector<ll> score(90001);
  for(int i=1;i<=H*W;i++){
    if(i<=D) score[i]=0;
    else{
      score[i]=score[i-D]
        +abs(T[i-D].first-T[i].first)
        +abs(T[i-D].second-T[i].second);
    }
  }
  int Q;
  cin>>Q;
  int L,R;
  for(int i=0;i<Q;i++){
    cin>>L>>R;
    cout<<score[R]-score[L]<<endl;
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=25,M=1e9+7;
int n;
int v[mxN];
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        if(v[i]<max(v[i+1],v[i-1]) && v[i]>min(v[i+1],v[i-1]))ans++;
    }
    cout<<ans;
}

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

int main(){
	int n, m; cin >> n >> m; std::vector<bool> li(n, false), li2(n, false);
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		if(a > b) std::swap(a, b);
		a--; b--;
		if(a == 0) li[b] = true;
		if(b == n - 1) li2[a] = true;
	}
	
	for(int i = 0; i < n; i++){
		if(li[i] and li2[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
int n,t;
int a[10005],b[10005];
int main(){
	cin>>n>>t;
	int ans1=1000000;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		if(b[i]<=t)ans1=min(ans1,a[i]);
	}
	if(ans1!=1000000)
	cout<<ans1;
	else  cout<<"TLE";
    return 0;
}

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

using st = struct {
	int a;
	int c;
};

int main() {
	ll h;
	cin >> h;

	ll a = 0;
	ll count = 1;
	while (h >= 1)
	{
		h /= 2;
		a += count;
		count *= 2;
	}

	cout << a;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

struct Union_find{
    vector<int> par;
    vector<int> cnt;
    Union_find(int p){
        par = vector<int>(p + 1);
        cnt = vector<int>(p + 1, 1);
        for(int i = 1; i <= p; i++){
            par[i] = i;
        }
    }
    int find(int x){
        if(par[x] == x)
            return x;
        else{
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(cnt[x] < cnt[y]){
            par[x] = y;
            cnt[y] += cnt[x];
        } else{
            par[y] = x;
            cnt[x] += cnt[y];
        }
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int get_cnt(int x){
        return cnt[find(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> g(m);
    for(int i = 0; i < m; i++){
        cin >> g[i].first >> g[i].second;
    }
    vector<ll> ans(m);
    ans[m - 1] = (ll)n * (n - 1) / 2;
    Union_find uf(n);
    for(int i = m - 1; i > 0; i--){
        int x = g[i].first, y = g[i].second;
        ans[i - 1] = ans[i];
        if(!uf.same(x, y)){
            ans[i - 1] -= (ll)uf.get_cnt(x) * uf.get_cnt(y);
        }
        uf.unite(x, y);
    }
    for(auto&& i : ans){
        cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int main(void)
{
	int jou,suu,ri,ei,s;
	int jou2,suu2,ri2,ei2,t;
	scanf("%d %d %d %d",&jou,&suu,&ri,&ei);
	scanf("%d %d %d %d",&jou2,&suu2,&ri2,&ei2);
	s=jou+suu+ri+ei;
	t=jou2+suu2+ri2+ei2;
		if(s<t){
			printf("%d\n",t);
		}
		else if(s==t){
			printf("%d\n",s);
		}
		else{
			printf("%d\n",s);
		}
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    reverse(a.begin(), a.end());

    vector<int> dp;
    dp.push_back(a[0]);

    rep1(i, n){
        if(a[i] >= dp.back()) dp.push_back(a[i]);
        else{
            int idx = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
            dp[idx] = a[i];
        }
        // rep(i, dp.size()) cout << dp[i] << " ";
        // cout << endl;
    }

    cout << dp.size() << endl;

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll ret;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>x, ret+=x-1;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main(){
  ll n, k, x, y;
  cin >> n >> k >> x >> y;
  ll ans = min(n, k) * x;
  ans += max(0LL, n - k) * y;
  cout << ans << endl;
}

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

#define ll long long
int c[502][502];
int D[35][39];
int t[3][30];

int main(){
    int N, C;
    cin >> N >> C;
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            cin >> D[i][j];
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> c[i][j];
            t[(i+j)%3][c[i][j]-1]++;
        }
    }
    int ans =1e9;
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            if(i != j){
                for(int k = 0; k < C; k++){
                    if ( i != k && j != k ){
                        int tt = 0;
                        for(int l = 0; l < C; l++) tt += D[l][i]* t[0][l];
                        for(int l = 0; l < C; l++) tt += D[l][j]* t[1][l];
                        for(int l = 0; l < C; l++) tt += D[l][k]* t[2][l];
                        ans = min(ans, tt);
                    }
                }
            }
        } 
    }

    cout << ans << endl;

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
const ld pi=3.141592653589793238;

const ll N=1e6+7;

void func()
{
  ll k;
  cin>>k;
  ll curr=0;
  f(i,1,N)
  {
    curr=(curr*10LL)%k;
    curr=(curr+7)%k;
    if(!curr) 
    {
      cout<<i<<"\n";
      return;
    }
  }

  cout<<"-1\n";
}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
    }
     
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <climits>
using namespace std;

string s;
int p;

int err = 0;

int number();
pair<int,int> expr(int needOp);

void chk(int v){
	if( v < 0 || v >= 1024 ) throw(3);
}

int isop(char c){
	return c == '+'||c == '-'||c == '*';
}
int expression(int needOp){
	pair<int,int> cc = expr(0);
	int l = cc.second;
	if( cc.first ) needOp = 0;
	
	int flag = 0;
	while(s[p] == '+' || s[p] == '-'){
		if( s[p] == '+' ){p++; l += expr(0).second;chk(l);}
		else if( s[p] == '-' ){p++; l -= expr(0).second;chk(l);}
		flag = true;
	}
	chk(l);
	if(needOp && !flag) throw(0);;
	return l;
}
pair<int,int> expr(int needOp){
	int l = number();
	int flag = 0;
	while( s[p] == '*' ){
		flag = true;
		if( s[p] == '*' ){p++; l *= number();chk(l);}
	}
	if(needOp && !flag) throw(0);
	chk(l);
	return make_pair(flag,l);
}

int number(){
	if( s[p] == '(' ){
		p++;
		int l = expression(1);
		if( p >= s.size() || s[p] != ')' ) throw(1);
		p++;
		return l;
	}
	int ans = 0;
	if( s[p] != '0' && s[p] != '1' ) throw(4);
	
	while( s[p] >= '0' && s[p] <= '1' ){
		ans = ans * 2 + s[p++] - '0';
		chk(ans);
	}
	return ans;
}

vector<int> pos;

int ans = -1;

void dfs(int x){
	if( x >= pos.size()){
		p = 0;
		try{
			int get = expression(0);
			if( p != s.size() ) throw(0);
			//cout << s << endl;
			
			ans = max(ans,get);
		}catch(int x){
			//cout << s << " " << x << endl;
		}
	}else{
		for(int i = 0 ; i < 7 ; i++){
			s[pos[x]] = "01+-*()"[i];
			dfs(x+1);
		}
	}
	
}

int main(){
	cin >> s;
	for(int i = 0 ; i < s.size() ; i++){
		if(s[i] =='.')pos.push_back(i);
	}
	
	dfs(0);
	cout << ans << endl;
}

Measured memory_bytes: 1272
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[150];
int main()
{
	scanf("%s",s);
	int len=strlen(s),ans=0;
	for(int i=0;i<=len/2-1;i++)
		if(s[i]!=s[len-1-i]) ans++;
	printf("%d",ans);
	return 0;
}

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

int main()
{
	string s;
	cin >> s;
	if (s[0] != 'A')
	{
		cout << "WA";
		return 0;
	}
	int ccnt = count(s.begin(), s.end(), 'C');
	if ( ccnt > 1|| ccnt==0)
	{
		cout << "WA";
		return 0;
	}
	int cpos = s.find('C', 0);
	if ( cpos< 2||cpos==s.length()-1)
	{
		cout << "WA";
		return 0;
	}
	string substr1 = s.substr(1, cpos-1);
	string substr2 = s.substr(cpos + 1, s.length() - (cpos + 1));
	if (*min_element(substr1.begin(), substr1.end()) < 97 || *min_element(substr2.begin(), substr2.end()) < 97)
	{
		cout << "WA";
		return 0;
	}
	cout << "AC";
	return 0;
}

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

int main(){
  long long N, L;
  cin >> N >> L;
  map<long long, long long> M;
  M[L] = 1;
  vector<pair<long long,long long>> V;
  for(long long i = 0; i < N; ++i){
    long long l, r;
    cin >> l >> r;
    M[l] = 1;
    M[r] = 1;
    V.emplace_back(l,r);
  }
  long long n = 0;
  for(auto &p : M){
    p.second = n++;
  }
  L = M[L];
  vector<long long> I(L+1,0);
  vector<pair<long long,long long>> T;
  for(long long i = 0; i < N; ++i){
    V[i].first = M[V[i].first];
    V[i].second = M[V[i].second];
    ++I[V[i].first];
    --I[V[i].second];
    T.emplace_back(V[i].first,-V[i].second);
  }
  sort(T.begin(),T.end());
  long long r = 0, x = 0, j = 0;
  while(r < L){
    long long nex_r = r;
    for(;j < N and T[j].first <= r; ++j){
      nex_r = max(nex_r,-T[j].second);
    }
    r = nex_r;
    ++x;
  }
  long long t = N;
  for(long long i = 1; i <= L; ++i){
    I[i] += I[i-1];
    t = min(t,I[i-1]);
  }
  long long y = N - t + 1;
  cout << x << " " << y << endl;
}



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

int main(void){
	int w,h;
	while(cin >> h >> w,h|w){
		int aw=200,ah=200;
		bool ok=false;
		int cmin=100000;
		int d=w*w+h*h;
		for(int ch=1;ch<151;ch++){
			for(int cw=ch+1;cw<151;cw++){
				if(!ok&&d==cw*cw+ch*ch&&ch>h){
					aw=cw,ah=ch,ok=true;
					cout << ah << " "<< aw << endl; 
					break;
				}
				if(cw*cw+ch*ch>d)
					cmin=min(cmin,cw*cw+ch*ch);
			}
		}
		if(ok)
			continue;
		else{
			for(int ch=1;ch<151;ch++){
				for(int cw=ch+1;cw<151;cw++){
					if(cmin==cw*cw+ch*ch&&ah>ch)
						aw=cw,ah=ch;
				}
			}
		}
		cout << ah << " " << aw << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const in inf=1e9+7;
using P=pair<in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in n,m;
    cin>>n>>m;
    using T=tuple<in,in,in>;
    in x,y,z;
    priority_queue<P, vector<P>, greater<P>> que;
    priority_queue<T, vector<T>, greater<T>> hen;
    
    rep(i,m){
        cin>>x>>y>>z;
        x --,y --;
        hen.emplace(x,y,z);
    }
    vector<in> d(n,-1);
    d[0]=0;
    in now=1;
    while(!hen.empty()){
        tie(x,y,z)=hen.top();
        if(x==0){
            que.emplace(z,y);
            hen.pop();
        }
        else break;
    }

    while(!que.empty() && d[n-1]==-1){
        tie(x,y)=que.top();
        if(y<now){
            que.pop();
            continue;
        }
        d[now]=x;
        while(!hen.empty()){
            tie(x,y,z)=hen.top();
            if(x!=now) break;
            hen.pop();
            que.emplace(z+d[now],y);
        }
        now ++;
    }
    cout<<d[n-1]<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(x,y) for(lli i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli x;
    cin>>x;
    lli ans=0;
    ans=ans+(x/500)*1000;
    x=x%500;
    ans=ans+(x/5)*5;
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s_a = []
for _ in range(H):
    s = list(input())
    s_a.append(s)

check_list = [(0,1),(0,-1),(1,0),(-1,0)]

def check(i,j):
    for x,y in check_list:
        try: 
            if s_a[i+x][j+y] == '#':
                return True
        except:
            continue
    return False

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if s_a[i][j] == '#':
            if check(i,j):
                continue
            else:
                ans = 'No'
                break
print(ans) 

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int flag = 0;
    if (n % 10 == 7) flag = 1;
    n /= 10;
    if (n % 10 == 7) flag = 1;
    n /= 10;
    if (n == 7) flag = 1;
    if (flag) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

string s;
int main() {
	cin >> s;
	if((int)s.size()%2) return puts("No")*0;
	for(int i=0; s[i]; i++) {
		if(i%2==0 && s[i]!='h' || i%2==1 && s[i]!='i') return puts("No")*0;
	}
	return puts("Yes")*0;
}

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

int main(int argc, char const *argv[])
{
	long long a,b;
	cin>>a>>b;
	if (a%b==0LL)
	{
		cout<<"-1\n";
	}
	else
	{
		cout<<a<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140148
N,k = map(int,input().split())
S = input()
if S[k-1] =='A':
  print(S[:(k-1)]+'a'+S[k:])
elif S[k-1] =='B':
  print(S[:(k-1)]+'b'+S[k:])
elif S[k-1] =='C':
  print(S[:(k-1)]+'c'+S[k:])
  

Measured memory_bytes: 2940
#include<cstdio>
#include<cctype>
#include<algorithm>
namespace fast_IO
{
	const int IN_LEN=1000000,OUT_LEN=1000000;
	char ibuf[IN_LEN],obuf[OUT_LEN],*ih=ibuf+IN_LEN,*oh=obuf,*lastin=ibuf+IN_LEN,*lastout=obuf+OUT_LEN-1;
	inline char getchar_(){return (ih==lastin)&&(lastin=(ih=ibuf)+fread(ibuf,1,IN_LEN,stdin),ih==lastin)?EOF:*ih++;}
	inline void putchar_(const char x){if(oh==lastout)fwrite(obuf,1,oh-obuf,stdout),oh=obuf;*oh++=x;}
	inline void flush(){fwrite(obuf,1,oh-obuf,stdout);}
}
using namespace fast_IO;
//#define getchar() getchar_()
//#define putchar(x) putchar_((x))
//#include<ctime>
#define rg register
typedef long long ll;
template <typename T> inline T max(const T a,const T b){return a>b?a:b;}
template <typename T> inline T min(const T a,const T b){return a<b?a:b;}
template <typename T> inline void mind(T&a,const T b){a=a<b?a:b;}
template <typename T> inline void maxd(T&a,const T b){a=a>b?a:b;}
template <typename T> inline T abs(const T a){return a>0?a:-a;}
template <typename T> inline void swap(T&a,T&b){T c=a;a=b;b=c;}
//template <typename T> inline void swap(T*a,T*b){T c=a;a=b;b=c;}
template <typename T> inline T gcd(const T a,const T b){if(!b)return a;return gcd(b,a%b);}
template <typename T> inline T lcm(const T a,const T b){return a/gcd(a,b)*b;}
template <typename T> inline T square(const T x){return x*x;};
template <typename T> inline void read(T&x)
{
	char cu=getchar();x=0;bool fla=0;
	while(!isdigit(cu)){if(cu=='-')fla=1;cu=getchar();}
	while(isdigit(cu))x=x*10+cu-'0',cu=getchar();
	if(fla)x=-x;
}
template <typename T> inline void printe(const T x)
{
	if(x>=10)printe(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(const T x)
{
	if(x<0)putchar('-'),printe(-x);
	else printe(x);
}
const int mod=1000000007;
int n;
char s[100001];
int tot[26];
ll ans=1;
int main()
{
	scanf("%d %s",&n,s+1);
	for(rg int i=1;i<=n;i++)tot[s[i]-'a']++;
	for(rg int i=0;i<26;i++)ans=ans*(tot[i]+1)%mod;
	print(ans-1);
	return flush(),0;
}

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) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            long n = Long.parseLong(str[0]);
            long m = Long.parseLong(str[1]);
            long total = 0;
            if (n > 0) {
                if (m >= 2) {
                    long temp = m / 2;
                    if (n > temp) {
                        total = temp;
                    } else {
                        total = n;
                        m -= n * 2;
                        total += m / 4;
                    }
                }
            } else {
                total += m / 4;
            }
            System.out.println(total);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 20692