akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define lll __int128
#define ull unsigned long long
#define fi first
#define se second
#define db double
#define ld long double
#define lld __float128

/// order_of_key, find_by_order

template<class T, class COMP>
using custom_set = tree<T, null_type, COMP, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd_64(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    ll n, k, s; cin >> n >> k >> s;
    if(s == (ll)1e9)
    {
        for(int i = 0; i < k; i++)
        {
            cout << s << ' ';
        }
        for(int i = k; i < n; i++)
        {
            cout << 1 << ' ';
        } cout << endl;
    }
    else
    {
        for(int i = 0; i < k; i++)
        {
            cout << s << ' ';
        }
        for(int i = k; i < n; i++)
        {
            cout << (ll)1e9 << ' ';
        } cout << endl;
    }
}






































/// shche ne vmerla Ykraina


Measured memory_bytes: 1280
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
def solve():
  n,k= (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  ans = 'IMPOSSIBLE'
  if max(a) < k :
    return ans
  elif k in a:
    ans = 'POSSIBLE'
    return ans
  else:
    gcd = gcd_list(a)
    #print(gcd)
    if gcd == 1 or k%gcd == 0 :ans ='POSSIBLE'
    return ans
       
  
  
  return ans
if __name__ == '__main__':
  print(solve())

Measured memory_bytes: 16308
#include <algorithm>
#include <iostream>
#include <vector>

const std::string kKeyence = "keyence";
bool check(const std::string& input, size_t idx, size_t next_keyence_idx, bool has_skipped) {
  if (next_keyence_idx == kKeyence.size()) {
    if (input.size() == idx || !has_skipped) {
      return true;
    } else {
      return false;
    }
  }

  if (input.size() == idx)
    return false;

  // Non-skip
  // Try to use input[idx].
  if (input[idx] == kKeyence[next_keyence_idx]) {
    bool ret = check(input, idx + 1, next_keyence_idx + 1, has_skipped);
    if (ret)
      return true;
  }

  // Skip
  // Not use input[idx].
  if (!has_skipped) {
    for (size_t i = idx + 1; i < input.size(); i++) {
      bool ret = check(input, i, next_keyence_idx, true);
      if (ret)
        return true;
    }
  }
  return false;
}
int main() {
  std::string input;
  std::cin >> input;
  std::cout << ((check(input, 0, 0, false)) ? "YES" : "NO") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int x[n];
    for(int i = 0;i < n;i++)
    {
        cin >> x[i];
    }
    int ans = INT_MAX;
    for(int i = 1;i <= 100;i++)
    {
        int temp = 0;
        for(int j = 0;j < n;j++)
        {
            temp += (i - x[j]) *(i - x[j]) ;
        }
        if(temp < ans)
        {
            ans = temp;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
k,e=' key = ',', '
input()
A=[0]+input().split()
H=len(A)
for i in range(1,H):
 print(f'node {i}: key = {A[i]}, {"parent"+k+A[i//2]+e if i>1 else""}{"left"+k+A[2*i]+e if 2*i<H else""}{"right"+k+A[2*i+1]+e if 2*i+1<H else""}')


Measured memory_bytes: 5596
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

namespace my
{
	//-----------------------------------------------------------------------------
	inline char cn()
	{
		static char buf[1000010],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
	}
	#define cn getchar
	template<class TY>void read(TY &x)
	{
		x=0;int f1=1;char ch=cn();
		while(ch<'0'||ch>'9'){if(ch=='-')f1=-1;ch=cn();}
		while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=cn(); x*=f1;
	}
	char Output[1000100],Zk[100];int op_top=0,Zk_top;
	void fcheck(int Type=0){if(Type||op_top>=1000000)fwrite(Output,1,op_top,stdout),op_top=0;}
	template<class TY>inline void write(TY x)
	{
		if(x==0){Output[op_top++]='0';fcheck();return;}
		if(x<0)Output[op_top++]='-',x=-x;
		Zk_top=0;while(x)Zk[++Zk_top]=x%10+'0',x/=10;
		while(Zk_top)Output[op_top++]=Zk[Zk_top--];fcheck();
	}
	#define K_G Output[op_top++]=' '
	#define H_C Output[op_top++]='\n'
	//--------------------------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------------------------
	#define ll long long
	#define uint unsigned int
	#define ull unsigned long long
	#define INV(x) ksm(x,mod-2)
	#define inf 999999999
	#define mod 998244353
	
	template<class TY>void add(TY &x,TY y){x=(x+y>=mod?x+y-mod:x+y);}
	template<class TY>void dec(TY &x,TY y){x=(x-y<0?x-y+mod:x-y);}
	template<class TY>TY add(TY x){return x>=mod?x-mod:x;}
	template<class TY>TY dec(TY x){return x<0?x+mod:0;}
	//
	int ksm(int x,int y){int re=1;for(;(y&1?re=1ll*re*x%mod:0),y;y>>=1,x=1ll*x*x%mod);return re;}
	int *fac,*inv_fac,*inv;
	void work_math(const int N)
	{
		fac=new int[N+5];inv_fac=new int[N+5];inv=new int[N+5];
		inv[1]=1;for(int i=2;i<=N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fac[0]=inv_fac[0]=1;for(int i=1;i<=N;i++)fac[i]=1ll*fac[i-1]*i%mod;
		inv_fac[N]=INV(fac[N]);
		for(int i=N-1;i>=1;i--)inv_fac[i]=1ll*inv_fac[i+1]*(i+1)%mod;
	}
	int C(int x,int y){return 1ll*fac[x]*inv_fac[y]%mod*inv_fac[x-y]%mod;}
	//
	template<class TY>TY gcd(TY x,TY y){return !y?x:gcd(y,x%y);}
	template<class TY>TY exgcd(TY a,TY b,TY &x,TY &y){
		if(!b)return x=1,y=0,a;
		TY re=exgcd(b,a%b,y,x);
		return y-=a/b*x,re;
	}
	//
	template<class TY>void discretization(TY *arr,int St,int Ed){
		vector<TY>Arr;Arr.clear();
		for(int i=St;i<=Ed;i++)Arr.push_back(arr[i]);
		sort(Arr.begin(),Arr.end());
		for(int i=St;i<=Ed;i++)arr[i]=lower_bound(Arr.begin(),Arr.end(),arr[i])-Arr.begin()+1;
	}
	//-----------------------------------------------------------------------------------------------
	
	//----------------------------------------------------------------------------------------------- 
	int a,b,c;
	
	void main()
	{
		read(a);read(b);read(c);
		c-=min(c,a-b);
		write(c);
		fcheck(1);return;
	}
}

int main(){my::main();return 0;}

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

int main(){
  int M1,D1,M2,D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if(M1 != M2){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n=9,i,sum=0;
    for(n=1;n<=9;n++)
    {
        for(i=1;i<=9;i++)
        {
            sum=n*i;
            printf("%dx%d=%d\n",n,i,sum);
        }
    }
    return 0;
}



Measured memory_bytes: 1932
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define gloop(n) for(ll g=0; g<(n); g++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll LINF = 2e17+423;
const int INF = 2e9 + 69;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);






































int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = len(s);
    string t = s.substr(0, n/2);
    reverse(all(s));
    string tt = s.substr(0, n/2);
    int ams=0;
    loop(n/2) if(t[i]!=tt[i]) ams++;
    cout << ams << endl;

    R 0;
}
/*

*/



























































ll po(ll x, ll n){
  if(n==0) R 1%mod;
  ll y = po(x, n/2)%mod;
  y = ((y%mod)*(y%mod));
  if(n%2) y = (y*(x%mod))%mod;
  R y%mod;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int sx = scanner.nextInt();
		int sy = scanner.nextInt();
		int tx = scanner.nextInt();
		int ty = scanner.nextInt();
		String ans = "";

		ans += makeString("U", ty - sy);
		ans += makeString("R", tx - sx);
		ans += makeString("D", ty - sy);
		ans += makeString("L", tx - sx + 1);
		ans += makeString("U", ty - sy + 1);
		ans += makeString("R", tx - sx + 1);
		ans += makeString("D", 1);
		ans += makeString("R", 1);
		ans += makeString("D", ty - sy + 1);
		ans += makeString("L", tx - sx + 1);
		ans += makeString("U", 1);

		System.out.println(ans);
	}

	private static String makeString(String string, int n) {
		String s = "";
		for (int i = 0; i < n; i++) {
			s += string;
		}
		return s;
	}
}

Measured memory_bytes: 62292
# -*- coding: utf-8 -*-
# 整数の入力

s = input()
t = input()
# s = "ratcode"
# t = "atlas"

# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())
# # 文字列の入力
# s = input()
s = list(s)
t = list(t)
s.sort()
t.sort()
t.reverse()

t2 = ''.join(t)
s2 = ''.join(s)

print( "Yes" if s2 < t2 else "No")

# f =False
# for sc,tc in zip(s,t):
#   # print(sc+" "+tc)
#   if tc > sc:
#     f=True
#     break;
#   if tc < sc:
#     f=False
#     break;

# if f:
#   print("Yes")
# else:
#   print("No")

# 出力
# print("{} {}".format(a+b+c, s))

Measured memory_bytes: 3060
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		BigDecimal W = new BigDecimal(sc.next()) ;
		BigDecimal H = new BigDecimal(sc.next()) ;
		BigDecimal x = new BigDecimal(sc.next()) ;
		BigDecimal y = new BigDecimal(sc.next()) ;

		BigDecimal s = W.multiply(H).divide(new BigDecimal("2"));

		System.out.print(s + " ");
		BigDecimal wd = W.divide(new BigDecimal("2")) ;
		BigDecimal hd = H.divide(new BigDecimal("2")) ;
		if(	x.equals(wd) &&y.equals(hd) ){
			System.out.println(1);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long num[55],n,m,i,j;
int main()
{
	cin>>n;
	for (i=50;i>=2;i--)
	{
		for (j=1;j<=i;j++) num[j]=i-1-n;
		for (j=1;j<=i;j++) num[j]+=n/i*(i+1);
		for (j=1;j<=n%i;j++) num[j]+=i+1;
		bool bo=1;
		for (j=1;j<=i;j++) if (num[j]<0||num[j]>1e18) {bo=0;break;}
		if (bo)
		{
			cout<<i<<endl;
			for (j=1;j<=i;j++) cout<<num[j]<<' ';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<climits>
using namespace std;
typedef pair<long long,long long>P;
typedef pair<P,long long>PP;
int main(){
  long long n,m;
  long long s;
  long long min_cost[100][5000];
  vector<PP>node[100];
  cin>>n>>m>>s;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=5000;j++){
      min_cost[i][j]=LLONG_MAX;
    }
  }
  
  long long maxim=0;
  for(int i=0;i<m;i++){
    long long a,b;
    long long fee,minute;
    cin>>a>>b;
    cin>>fee>>minute;
    maxim=max(maxim,fee);
    node[a].push_back(PP(P(minute,fee),b));
    node[b].push_back(PP(P(minute,fee),a));
  }
  long long change[100];
  long long times[100];
  for(int i=1;i<=n;i++){
    cin>>change[i]>>times[i];
  }
  priority_queue<PP,vector<PP>,greater<PP> >pq;
  s=min(maxim*(n-1),s);
  min_cost[1][s]=0;
  pq.push(PP(P(0,s),1));
  while(!pq.empty()){
    PP now=pq.top();pq.pop();
    long long cost=now.first.first;
    long long coin=now.first.second;
    long long pos=now.second;
    //        cout<<endl<<endl<<"pos ="<<pos<<endl;
    //        cout<<"cost="<<cost<<endl;
    //        cout<<"coin="<<coin<<endl;
    for(int i=0;i<(int)node[pos].size();i++){
      long long next=node[pos][i].second;
      long long need=node[pos][i].first.second;
      long long ncost=node[pos][i].first.first+cost;
      long long ncoin;
      if(coin>=need){
	ncoin=coin-need;
      }else{
	ncoin=change[pos]-(need-coin)%change[pos];
	if(ncoin==change[pos]){
	  ncoin=0;
	}
	ncost+=(need-coin+change[pos]-1)/change[pos]*times[pos];
      }
      //            cout<<"  next ="<<next<<endl;
      while(ncoin<=maxim*(n-1)){
	//		cout<<"  ncost="<<ncost<<endl;
	//		cout<<"  ncoin="<<ncoin<<endl<<endl;
	if(ncost<min_cost[next][ncoin]){
	  min_cost[next][ncoin]=ncost;
	  pq.push(PP(P(ncost,ncoin),next));
	}
	ncost+=times[pos];
	ncoin+=change[pos];
      }
      ncoin=max(maxim*(n-1),ncoin);
      //            cout<<"  ncost="<<ncost<<endl;
      //            cout<<"  ncoin="<<ncoin<<endl<<endl;
      if(ncost<min_cost[next][ncoin]){
	min_cost[next][ncoin]=ncost;
	pq.push(PP(P(ncost,ncoin),next));
      }
    }
  }
  for(int i=2;i<=n;i++){
    long long minimum=LLONG_MAX;
    for(int j=0;j<=maxim*(n-1);j++){
      minimum=min(minimum,min_cost[i][j]);
    }
    cout<<minimum<<endl;
  }
  return(0);
}

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

int main()
{
	int n, m, x, ans = 0;
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		ans += min(x, m - x) * 2;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int n;
  cin >> n;
  int a[n];
  int mpo[100000]={};
  int mpe[100000]={};
  int count=0;
  REP(i, n) {
    cin >> a[i];
    if(i && a[i] == a[i-1]) ++count;
    if(i%2) ++mpo[a[i]];
    else ++mpe[a[i]];
  }
  if(count == n-1){
    cout << n/2 << endl;
    return 0;
  }

  int maxo=0, maxe=0, oi, ei, ans;
  REP(i, n){
    if(maxo < mpo[i]){
    maxo=max(maxo, mpo[i]);
      oi = i;
    }
    if(maxe < mpe[i]){
    maxe=max(maxe, mpe[i]);
      ei = i;
    }
  }
  sort(mpo, mpo + 100000, greater<int>());
  sort(mpe, mpe + 100000, greater<int>());
  if(oi != ei) {
    ans = n - mpo[0] - mpe[0];
  }
  else {
    ans = n - max(mpo[0] + mpe[1], mpe[0] + mpo[1]);
  }
  cout << ans << endl;
  return 0;
}


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


int main(){
    string s;
    cin >> s;
    int c=101,f=-1;
    rep(i,s.size()){
        if(s.at(i) == 'C'){
            c = min(c,i);
        }
        if(s.at(i) == 'F'){
            f = max(f,i);
        }
    }
    if(c < f) cout << "Yes" << endl;
    else cout << "No" << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,k;
signed main(){
	cin>>n>>k;
	if(k<=(n+1)/2)cout<<"YES"<<endl;
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll a, b;
  cin >> a >> b;
  string ans;
  
  if(0 < a) ans = "Positive";
  else if(a <= 0 and 0 <= b) ans = "Zero";
  else ans = ((b-a+1)%2==0 ?"Positive" :"Negative");
  
  cout << ans << "\n";

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        auto it_a = lower_bound(a.begin(), a.end(), b[i]);
        auto it_c = upper_bound(c.begin(), c.end(), b[i]);
        ans += (it_a - a.begin()) * (c.end() - it_c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <string>
#include <float.h>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

// Q1
int main()
{
	char szY[10];

	int A1;
	int A2;
	int A3;
	cin >> A1 >> A2 >> A3;
	if (21 < A1 + A2 + A3)
		cout << "bust";
	else
		cout << "win";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long k = sc.nextLong();
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    long ans = k;
    for(int i = 0; i < n; i++) {
      long t = 0;
      if(i == (n - 1)) {
        t = (k - a[n - 1]) + a[0];
      } else {
        t = a[i + 1] - a[i];
      }
      ans = Math.min(ans, k - t);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 85216
#include<stdio.h>
#include<math.h>
 
int main(){
    int a;
    scanf("%d",&a);
    int b=100000;
    for(int i=0;i<a;i++){
        b*=1.05;
        if(b%1000!=0)b=(b/1000+1)*1000;
    }
    printf("%d\n",b);
}

Measured memory_bytes: 1020
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int W,H,x,y,r;
        W = input.nextInt();
        H = input.nextInt();
        x = input.nextInt();
        y = input.nextInt();
        r = input.nextInt();
        int up,down,left,right;
        up = y + r;
        down = y - r;
        left = x - r;
        right = x + r;
        String ans;
        if ((up <= H) && (down >= 0) && (left >= 0) && (right <= W)) {
            ans = "Yes";
        } else {
            ans = "No";
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 26296
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

signed main(){
	int a, b;
	while(cin >> a >> b){
		if(a < b) swap(a, b);
		int g = gcd(a, b);
		int l = a * b / g;
		cout << g << " " << l << endl;
	}
}

Measured memory_bytes: 3000
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            string[] h = Console.ReadLine().Split(' ');
            var ls = new List<int>();
            var it = new List<int>();
            foreach(string st in h){
                it.Add(int.Parse(st));
                ls.Add(1);
            }

            for(int i=0; i<m; i++){
                string[] r = Console.ReadLine().Split(' ');
                int a = int.Parse(r[0]) - 1;
                int b = int.Parse(r[1]) - 1;
                if(it[a]<=it[b]) ls[a] = 0;
                if(it[b]<=it[a]) ls[b] = 0;
            }
            Console.WriteLine(ls.Sum());
        }
    }
}


Measured memory_bytes: 49472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
	ll k,s,i;
cin>>k;
s=7;
for(i=1;i<=k;i++)
{
	if(s%k==0)
	{
		cout<<i<<endl;
		return;
	}
	s=(s*10+7)%k;
}
cout<<-1<<endl;return; 


}






int main()
{
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif

	int t=1;
	//cin >> t;

	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 3592
# D - RGB Triplets
from collections import defaultdict


def main():
    _, S = open(0).read().split()
    indices, doubled_indices = defaultdict(list), defaultdict(set)
    for i, c in enumerate(S):
        indices[c].append(i)
        doubled_indices[c].add(2 * i)
    cnt = S.count("R") * S.count("G") * S.count("B")
    for x, y, z in ["RGB", "GBR", "BRG"]:
        cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y])
    print(cnt)


if __name__ == "__main__":
    main()


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

int main(void)
{
  int n, m;
  int i, j;
  int temp;
  int array[100];
  int gr[100][100];

  cin >> n >> m;
  
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      cin >> gr[i][j];
    }
  }

  for(j = 0; j < m; j++){
    cin >> array[j];
  }

  for(i = 0; i < n; i++){
    temp = 0;
    for(j = 0; j < m; j++){
      temp = temp + gr[i][j]*array[j];
    }
    cout << temp << endl;
  }

  return 0;
}

Measured memory_bytes: 3136
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 80;
const int M = 12800 + 10;
bitset<M * 2> dp[N][N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  // n = m = 80;
  vector<vector<int>> a(n, vector<int>(m));
  vector<vector<int>> b(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      // a[i][j] = rnd(81);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &b[i][j]);
      // b[i][j] = rnd(81);
    }
  }
  int x = a[0][0] - b[0][0];
  dp[0][0][M + x] = dp[0][0][M - x] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i + j == 0) continue;
      int x = abs(a[i][j] - b[i][j]);
      if (i - 1 >= 0) {
        dp[i][j] |= dp[i - 1][j] << x;
        dp[i][j] |= dp[i - 1][j] >> x;
      }
      if (j - 1 >= 0) {
        dp[i][j] |= dp[i][j - 1] << x;
        dp[i][j] |= dp[i][j - 1] >> x;
      }
      // trace(i, j, dp[i][j].size());
    }
  }
  int best = INF;
  for (int k = -M; k < M; ++k) {
    if (dp[n - 1][m - 1][M + k]) {
      best = min(best, abs(k));
    }
  }
  printf("%d\n", best);
  return 0;
}


Measured memory_bytes: 20352
import java.util.*;

class Clothes{
	public int small;
	public int large;
	public int hade;
	Clothes(int down, int up, int hd){
		small=down;
		large=up;
		hade=hd;
	}
}

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();//D：日数
		int N = sc.nextInt();//N：服の種類
		int[] wthr = new int[D];//温度の配列
		int[][] field = new int[N][];//動的計画法のフィールド
		int[][] field_result = new int[N][];//動的計画法での計算結果
		Clothes[] data = new Clothes[N];//服の情報のクラス配列
		for(int i=0; i<D; ++i) wthr[i]=sc.nextInt();
		for(int i=0; i<N; ++i){
			field[i] = new int[D];//N行D列
			field_result[i] = new int[D];
			data[i] = new Clothes(sc.nextInt(), sc.nextInt(), sc.nextInt());
		}		
		for(int j=0; j<D; ++j){
			for(int i=0; i<N; ++i){
				if(data[i].small <= wthr[j] && wthr[j] <= data[i].large){
					field[i][j]=data[i].hade;
					field_result[i][j]=0;
				}else{
					field[i][j]=-1;
					field_result[i][j]=-1;
				}
			}
		}
		for(int j=1; j<D; ++j){
			for(int i=0; i<N; ++i){
				if(field[i][j]==-1) continue;
				int big=0;
				int bigIndex=0;
				for(int k=0; k<N; ++k){
					if(field[k][j-1]==-1) continue;
					if(field_result[i][j] < Math.abs(field[k][j-1]-field[i][j])+field_result[k][j-1]){
						field_result[i][j] = Math.abs(field[k][j-1]-field[i][j])+field_result[k][j-1];				
//						System.out.println("k:"+k+" i:"+i+" j:"+j+" "+field_result[i][j]);
					}
				}
			}
		}
//最大値の検索
		int ans=field_result[0][D-1];
		for(int i=1; i<N; ++i){
			if(ans<field_result[i][D-1]) ans=field_result[i][D-1];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 24256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#define int long long
#define uint unsigned long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int a[50];
int b[50];
int c[50];
int d[50];

signed main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < M; i++)
	{
		cin >> c[i] >> d[i];
	}

	for (int i = 0; i < N; i++)
	{
		int ans = 0;
		int min = INT_MAX;
		for (int j = 0; j < M; j++)
		{
			int len = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (len < min)
			{
				ans = j;
				min = len;
			}
		}
		cout << (ans + 1) << endl;
	}
}


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

int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll ans=1;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        ans= boost::math::lcm(ans,a[i]);
    }    
    cout<<ans;
}


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

int main(){

  long N;
  long num, ans=0;
  cin >> N;
  num = N;
  while(num>0){
    ans += num%10;
    num/=10;
  }
  cout << (N%ans==0 ? "Yes" : "No") << endl;

 return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        int[] alpha = new int[26];
        Arrays.fill(alpha, 50);

        IntStream.range(0, Integer.parseInt(sc.next())).forEach(i -> {
            String str = sc.next();
            IntStream.rangeClosed('a', 'z').forEach(j ->
                    alpha[j - 'a'] = (int) Math.min(alpha[j - 'a'], str.chars().filter(k -> k == j).count())
            );
        });

        for (char i = 'a'; i <= 'z'; i++) {
            for (int j = 0; j < alpha[i - 'a']; j++) {
                System.out.print(i);
            }
        }
    }
}

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

int main() {
    int number = 0;
    cin >> number;
    long prepre = 2L;
    long pre = 1L;
    long result = 0;
    if (number == 0) {
        result = prepre;
    } else {
        result = pre;
    }
    for (int i = 2; i <= number; i++) {
        result = prepre + pre;
        if (i % 2 == 0) {
            prepre = result;
        } else {
            pre = result;
        }
    }
    
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int h,w,k,d[888][888],dx[]={-1,1,0,0},dy[]={0,0,-1,1};
char a[888][888];
void bfs(int x,int y)
{
	queue<pii> q;
	d[x][y]=0; q.push(pii(x,y));
	while(!q.empty())
	{
		pii s=q.front(); q.pop();
		for(int g=0;g<4;++g)
		{
			pii w=s; w.fi+=dx[g]; w.se+=dy[g];
			if(d[w.fi][w.se]<=d[s.fi][s.se]+1||a[w.fi][w.se]!='.') continue; 
			d[w.fi][w.se]=d[s.fi][s.se]+1; q.push(w);
		}
	}
}
int main()
{
	memset(d,127/3,sizeof d);
	scanf("%d%d%d",&h,&w,&k);
	int sx,sy;
	for(int i=1;i<=h;++i)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=w;++j)
			if(a[i][j]=='S') sx=i,sy=j,a[i][j]='.';
	}
	bfs(sx,sy);
	int ans=1e9;
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j) if(d[i][j]<=k)
		{
			int g=min(min(i-1,h-i),min(j-1,w-j));
			ans=min(ans,(g+k-1)/k); 
		}
	printf("%d\n",ans+1);
}


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

struct UnionFind {
    vector<ll> par;//iの親の番号
    
    UnionFind(int n) : par(n, -1) { }
	//xが属す根を求める
    ll root(ll x) {
        if (par[x] < 0){
			return x;
		}else{
			return par[x] = root(par[x]);
		}
    }
    
	//x,yが同じ根に属するかを判定
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
    
	//xとyの木を統合
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); 
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    ll size(ll x) {
        return -par[root(x)];
    }
};

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> A(M), B(M);
    for (ll i(0); i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }
    
    UnionFind uf(N);
    ll cur(N * (N-1) / 2);
    vector<ll> ans;
    for (ll i(M-1); i >= 0; --i) {
        ans.push_back(cur);
            
        ll a(A[i]), b(B[i]);
		//a,bが根を共有している場合，不便さは変わらない
        if (uf.issame(a, b)){
			continue;
		}
        //i番目の橋の追加により，a,bの木に属する島の組み合わせの数だけ不便さが減少
		else{
			ll sa(uf.size(a)), sb(uf.size(b));
        	cur -= sa * sb;
        	uf.unite(a, b);
		}
    }
        
    reverse(ans.begin(), ans.end());
    for (ll i(0); i < ans.size(); ++i) cout << ans[i] <<endl;

	return 0;
}

Measured memory_bytes: 4596
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
using namespace std;
char a[100050];
int k;
int main(){
	scanf("%s%d",a+1,&k);
	for(int i=1;i<=strlen(a+1);i++){
		if(k==0) break;
		if(i==strlen(a+1)){
			if(k%26<='z'-a[i]) a[i]+=k%26;
			else a[i]='a'+k%26-('z'-a[i]+1);
			k=0;
		}
		else if(a[i]=='a') continue;
		else if('z'-a[i]+1<=k){\
			k-='z'-a[i]+1;
			a[i]='a';
		}
	}
	printf("%s\n",a+1);
}

Measured memory_bytes: 384
use std::io;
use std::collections::*;
#[allow(dead_code)]
fn read() -> String
{
    let mut res = String::new();
    io::stdin().read_line(&mut res).unwrap();
    res
}
#[allow(unused_macros)]
macro_rules! read 
{
    () => 
    {
        read().trim().parse().unwrap();       
    };
}
#[allow(dead_code)]
fn read_vec() -> Vec<i64>
{
    read().split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect()
}
fn solve(a : &Vec<i64>, rem : usize, pos : usize, m : &mut HashMap<(usize, usize), i64>) -> i64
{
    let cur = (rem, pos);
    if let Some(val) = m.get(&cur)
    {
        return *val;
    }
    if rem == 0
    {
        m.insert(cur, 0);
        return 0;
    }
    if rem > (a.len() - pos + 1) / 2
    {
        m.insert(cur, std::i64::MIN);
        return std::i64::MIN;
    }
    let res = solve(a, rem, pos + 1, m).max(solve(a, rem - 1, pos + 2, m) + a[pos]);
    m.insert(cur, res);
    res
}
fn main()
{
    let (n, a, mut m) : (usize, Vec<i64>, HashMap<(usize, usize), i64>) = (read!(), read_vec(), HashMap::default());
    println!("{}", solve(&a, n / 2, 0, &mut m));
}

Measured memory_bytes: 37016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> A(5);
    for(int i = 0; i < 5; i++) {
        cin >> A.at(i);
    }
    for(int i = 0; i < 5; i++) {
        if(A.at(i) == 0){
            cout << i+1 << endl;    
        }
    }
    
}

Measured memory_bytes: 3548
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	if(c1+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500)>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define N 998244353
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i;
    string s;
    cin>>n>>s;
    if(n%2 == 1)
    {
        cout<<"No\n";
        return 0;
    }
    for(i=0;i<n/2;i++)
        if(s[i] != s[n/2+i])
        {
            cout<<"No\n";
            return 0;
        }
    cout<<"Yes\n";
    return 0;
}

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

#define ll long long
#define MAXN 3010
using namespace std;


string S;
int Q;
int T, F;
char C;

deque<char> q;

int main()
{
	cin>>S;
	for(int i = 0; i < (int)S.size(); ++i)
		q.push_back(S[i]);
	bool reverse = false;
	cin>>Q;
	for(int i = 0; i < Q; ++i)
	{
			cin>>T;
			if(T == 1)
			{
				reverse = !reverse;
			}
			else
			{
				cin>>F>>C;
				bool b = (bool)(F - 1);
				if((b^reverse) == 0)
				{
					q.push_front(C);
				}
				else
				{
					q.push_back(C);
				}
			}
	}
	string ans = "";
	if(reverse)
	{
		while(!q.empty())
		{
				ans += q.back();
				q.pop_back();
		}
	}
	else
	{
		while(!q.empty())
		{
				ans += q.front();
				q.pop_front();
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, m, q; cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for(int i = 0; i < q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  int ans = 0;
  auto dfs = [&](auto&& dfs, vector<int> v)->void{
    if(v.size() == n+1){
      int res = 0;
      for(int i = 0; i < q; i++){
        if(v[b[i]] - v[a[i]] == c[i]) res += d[i];
      }
      ans = max(ans, res);
      return;
    }
    
    v.push_back(v.back());
    while(v.back() <= m){
      dfs(dfs, v);
      v.back()++;
    }
  };
  dfs(dfs, vector<int>(1, {1}));
  cout << ans << endl;

  return 0;
}

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

int main(){
    int N;
    cin >>N;
    int j;
    for(int i=1; i<=9; i++){
        if( N%i==0 ){
            j=N/i;
            if( j<=9 ){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

typedef long long ll;

int n, m; ll t;
int s[300005]; char d[300005];
pair<int,int> o[300005];
int res[300005];

int main() {
    scanf("%d%d%lld", &n, &m, &t);
    FO(i,0,n) scanf("%d %d", s+i, d+i);
    FO(i,0,n) o[i] = make_pair(s[i],i);
    sort(o,o+n);
    vector<ll> p;
    ll nc = 0;
    FO(i,0,n) {
        int dir = d[i] == 2 ? -1 : 1;
        ll pos = s[i] + dir * t;
        ll fp = ((pos%m)+m)%m;
        ll g = pos > 0 ? pos / m : (pos-m+1) / m;
        nc += g;
        p.push_back(fp);
    }
    nc = ((nc%n)+n)%n;
    sort(p.begin(),p.end());
    FO(i,0,n) res[o[i].second] = p[(i+nc)%n];
    FO(i,0,n) printf("%d\n", res[i]);
}


Measured memory_bytes: 5492
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type card struct {
	mark string
	num  int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	valstr := sc.Text()
	n, _ := strconv.Atoi(valstr)

	sc.Scan()
	cardsStr := sc.Text()
	// cardsStr = "H4 C9 S4 D2 C3" // TODO
	cardStrs := strings.Split(cardsStr, " ")
	// n = 5 // TODO
	var cards1 []card
	for i := 0; i < n; i++ {
		card := split(cardStrs[i])
		cards1 = append(cards1, card)
	}

	var cards2 []card
	for i := 0; i < n; i++ {
		card := split(cardStrs[i])
		cards2 = append(cards2, card)
	}

	br := bubbleSort(n, cards1)
	print(br)
	fmt.Println("Stable")

	sr := selectionSort(n, cards2)
	print(sr)

	s := true
	for i := 0; i < n; i++ {
		if br[i].mark != sr[i].mark {
			fmt.Println("Not stable")
			s = false
			break
		}
	}

	if s {
		fmt.Println("Stable")
	}

}

func print(cards []card) {
	var s string
	for _, card := range cards {
		s = s + card.mark + strconv.Itoa(card.num) + " "
	}

	fmt.Println(strings.TrimSpace(s))
}

func bubbleSort(n int, cards []card) []card {
	for i := 0; i < n; i++ {
		for j := n - 1; j > i; j-- {
			if cards[j].num < cards[j-1].num {
				cards[j], cards[j-1] = cards[j-1], cards[j]
			}
		}
	}

	return cards
}

func selectionSort(n int, cards []card) []card {
	for i := 0; i < n; i++ {
		minj := i
		for j := i; j < n; j++ {
			if cards[j].num < cards[minj].num {
				minj = j
			}
		}
		cards[i], cards[minj] = cards[minj], cards[i]
	}
	return cards
}

func split(cardStr string) card {
	n, _ := strconv.Atoi(string(cardStr[1]))
	return card{string(cardStr[0]), n}
}



Measured memory_bytes: 1128
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

h,w = mi()
meiro = []
meiro.append("#"*(w+2))
for i in range(h):
    lis = "#" + input() + "#"
    meiro.append(lis)
#print(meiro[1][1])
meiro.append("#"*(w+2))

inf = 10 **4
aa = [1,0,-1,0]
ab = [0,1,0,-1]
ans = 0

from collections import deque
for i in range(1,h+1):
    for k in range(1,w+1):
        if meiro[i][k] == "#":
            continue
        dp = [[inf]*(w+2) for _ in range(h+2)]
        dp[i][k] = 0
        que = deque()
        que.append((i,k,0))
        while que:
            hh, ww,num = que.popleft()
            for l in range(4):
                hnext = hh + aa[l]
                wnext = ww + ab[l]
                if meiro[hnext][wnext] != "#" and dp[hnext][wnext] > (num +1):
                    dp[hnext][wnext] = num+1
                    que.append((hnext,wnext,num+1))
        ans = max(ans,num)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,M; cin>>N>>M;
    string S; cin>>S;
    //reverse(ALL(S));
    vector<int> ans;
    int now = N;
    bool flag = true;
    while(now > 0){
        int count = min(M,now);
        while(S[now - count] == '1'){
            count--;
            if(count == 0){
                flag = false;
                break;
            }
        }
        if(!flag)break;
        ans.push_back(count);
        now -= count;
        //cout << now <<" " << count<< endl;
    }
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    for(int i = ans.size()-1; i>0; i--){
        cout << ans[i]<< " ";
    }
    cout << ans[0]<<endl;

}

Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 4e5+5;

vector<int> G[maxn];
int ans = 0;
int ing[maxn] = {};
bool vis[maxn] =  {};
int dp[maxn] = {};
void dfs(int now) {
	vis[now] = 1;
	for (int k:G[now]) {
		dp[k] = max(dp[k], dp[now] + 1);
		ing[k]--;
		if (!ing[k])
			dfs(k);
	}
}

main() {
	IOS
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		G[u].pb(v);
		ing[v]++;
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i] && !ing[i]) {
			dfs(i);
		}
	}
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		mx = max(mx, dp[i]);
	}
	cout << mx << "\n";
}


Measured memory_bytes: 22472
IDENTIFICATION DIVISION.
        PROGRAM-ID. ABC150_A.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 K PIC 9(15).
        01 X PIC 9(15).
        01 TMP PIC 9(15).
        01 INPUT_LINE PIC X(15).
        01 P1 PIC 9 VALUE 1.
        01 P2 PIC 9.
      
        PROCEDURE DIVISION.
        MAIN.
            ACCEPT INPUT_LINE.
            PERFORM VARYING P2 FROM 1 BY 1
                UNTIL INPUT_LINE(P1 + P2:1) = SPACE
            END-PERFORM
            MOVE INPUT_LINE(P1:P2) TO K
            ADD P2+1 TO P1

            PERFORM VARYING P2 FROM 1 BY 1
                UNTIL INPUT_LINE(P1 + P2:1) = SPACE
            END-PERFORM
            MOVE INPUT_LINE(P1:P2) TO X

            COMPUTE TMP = 500 * K.
            IF TMP >= X THEN
                DISPLAY "Yes"
            ELSE
                DISPLAY "No"
            END-IF

            STOP RUN.


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

vector<ll> graph[200005];
vector<ll> visitg(200005,false);
vector<ll> vrr;
void dfs(ll a, vector<ll> &visitg){
    if(!visitg[a]){
        vrr.back()++; visitg[a]=true;
        for(auto i:graph[a]) dfs(i,visitg);
    }
}
void solve(ll ts){
    ll n,m; cin>>n>>m; set<ll> st;
    rep(m){
        ll a,b; cin>>a>>b; graph[a].append(b); graph[b].append(a);
    }
    rep(n){
        if(!visitg[i+1]){
            vrr.append((ll)0);
            dfs(i+1,visitg);
        }
    }
    cout<<(*max_element(all(vrr)))<<endl;
} 
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 21848
border = 101


def manhattan_distance(Cx, Cy, H, X, Y):
    return max(H - abs(X - Cx) - abs(Y - Cy), 0)


def judge_center(Cx, Cy, cords):
    for x, y, h in cords:
        if h > 0:
            H = abs(x - Cx) + abs(y - Cy) + h
            break
    for x, y, h in cords:
        tmp = manhattan_distance(Cx, Cy, H, x, y)
        if (h > 0 and h != tmp) or (h == 0 and h < tmp):
            return -1
    return H


def main():
    N = int(input())
    cords = [list(map(int, input().split(' '))) for _ in range(N)]

    for tmp_Cx in range(border):
        for tmp_Cy in range(border):
            h = judge_center(tmp_Cx, tmp_Cy, cords)
            if h != -1:
                print('{} {} {}'.format(tmp_Cx, tmp_Cy, h))
                return 0


if __name__ == '__main__':
    main()


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

// int dp[100005];

// int dfs(int x, vector<int> e[])
// {
//     if(dp[x]!=-1)
//         return dp[x];
//     int ans=0;
//     for(int i=0;i<e[x].size();i++)
//     {
//         ans=max(ans,dfs(e[x][i],e)+1);
//     }
//     dp[x]=ans;
//     return dp[x];
// }

// void solve()
// {
//     int n,m,ans=0;
//     cin>>n>>m;
//     vector<int> e[n+1];
//     for(int i=0;i<m;i++)
//     {
//         int x,y;
//         cin>>x>>y;
//         e[x].push_back(y);
//     }
//     for(int i=1;i<=n;i++)dp[i]=-1;
//     for(int i=1;i<=n;i++)
//     {
//         ans=max(ans,dfs(i,e));
//     }
//     cout<<ans<<"\n";
// }

// int main()
// {
//     ios_base::sync_with_stdio(false);
//     cin.tie(NULL);
//     cout.tie(NULL);
//     solve();
//     return 0;
// }
#include <bits/stdc++.h>
using namespace std;

int dp[100005];
int d[100005];
void dfs(int x, vector<int> e[])
{
    if(d[x]!=-1)
        return;
    dp[x]=0;
    if(!e[x].size())
        dp[x]=1;
    for(int i=0;i<e[x].size();i++)
    {
        dfs(e[x][i],e);
        dp[x]=max(dp[x],d[e[x][i]]+1);
    }
    d[x]=dp[x];
}

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> e[n+1];
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        e[x].push_back(y);
    }
    for(int i=1;i<=n;i++)d[i]=-1;
    for(int i=1;i<=n;i++)
        dfs(i,e);
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,dp[i]-1);
    cout<<ans<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> edges[100010];
vector<bool> used;
bool ans = false;

void dfs(int i,int p = -1) {
    int cnt = 0;
    for (int& j : edges[i]) if (j != p) {
        dfs(j,i);
        if (!used[j]) cnt++;
    }
    if (cnt > 1) ans = true;
    else if (cnt) used[i] = true;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    used.resize(n,false);
    dfs(0);
    cout << (ans || !used[0] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 5888