akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
@SuppressWarnings("unchecked")
class Main {
	static LinkedList<Integer>[] graph;

	public static void solve(int n){
		int[] distance = new int[n];
		int[] visited = new int[n];
		int[] marks = new int[distance.length];
		Queue<Integer> q = new LinkedList<>();
		q.add(1);
		while(!q.isEmpty()){
			int poll = q.poll();
			for(int child : graph[poll]){
				if(visited[child] == 0){
					distance[child] = distance[poll]+1;
					marks[child] = poll;
					visited[child] = 1;
					q.add(child);
				}
			}
		}		

		//System.out.print(Arrays.toString(distance));
	 System.out.println("Yes");
    for(int i = 2; i < marks.length; i++){
      System.out.println(marks[i]);
    }

	}


	public static void main(String[] args) throws Exception {
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     	 String[] in = br.readLine().trim().split(" ");
		int n = Integer.parseInt(in[0]);
		n = n+1;
		int e = Integer.parseInt(in[1]);
		graph = new LinkedList[n];
		for(int i = 0; i < n; i++)
			graph[i] = new LinkedList<Integer>();



		for(int i = 0;i<e;i++){
			in = br.readLine().trim().split(" ");
			int a = Integer.parseInt(in[0]);
			int b = Integer.parseInt(in[1]);
			graph[a].add(b);
			graph[b].add(a);


}
          solve( n);


   

	}
}

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

int main() {
  string s;
  cin >> s;

  string a = "";
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'B') {
      if (a.length() >= 1) {
        a.erase(a.length() - 1);
      }
    } else {
      a.append(1, s.at(i));
    }
  }

  cout << a << endl;
  return 0;
}


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

#define N 100
#define T 200

int t[N];
int limit[N * T * 2];
double acc[N * T * 2 + 1];

int main()
{
	double ans;
	int n;

	cin >> n;
	for( int i = 0; i < n; i++ ) {
		cin >> t[i];
	}
	int total = 0;
	for( int i = 0; i < n; i++ ) {
		int v;
		cin >> v;
		for( int j = total * 2; j < (total + t[i]) * 2; j++ ) {
			limit[j] = v;
		}
		total += t[i];
	}

	acc[0] = 0;
	for( int i = 0; i < total * 2; i++ ) {
		acc[i + 1] = min( acc[i] + 0.5, (double)limit[i] );
	}
	acc[total * 2] = 0;
	for( int i = total * 2 - 1; i >= 0; i-- ) {
		acc[i] = min( acc[i], min( acc[i + 1] + 0.5, (double)limit[i] ) );
	}
	for( int i = 0; i < total * 2; i++ ) {
		ans += (acc[i] + acc[i + 1]) * 0.5 / 2;
	}

	cout << fixed << setprecision(4) << ans << endl;

	return 0;
}


Measured memory_bytes: 768
N,M=map(int,input().split())
if abs(N-M)>1:
    print(0)
else:
    if N<M: N,M = M,N
    mod = 10**9+7
    f = 1
    for i in range(2,M+1):
        f = f*i%mod
    ans = f*f*(2 if N==M else N)%mod
    print(ans)

Measured memory_bytes: 3064
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define mINF -1e9
#define endl "\n"
#define CONT continue
#define BRK break

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
//here begins your code
int N;
vll a;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  a.resize(3*N);
  REP(i,3*N){
    cin >> a[i];
  }


    vector<long long> S(N*2+1, 0);
    priority_queue<long long, vector<long long>, greater<long long> > que1;
    for (int i = 0; i < N; ++i) {
        S[i+1] = S[i] + a[i];
        que1.push(a[i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long mi = que1.top();
        if (a[i] > mi) {
            S[i+1] = S[i] - mi + a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else S[i+1] = S[i];
    }

    vector<long long> T(N*2+ 1, 0);
    priority_queue<long long> que2;
    for (int i = 0; i < N; ++i) {
        T[i+1] = T[i] + a[N*3-1 - i];
        que2.push(a[N*3-1 - i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long ma = que2.top();
        if (a[N*3-1 - i] < ma) {
            T[i+1] = T[i] - ma + a[N*3-1 - i];
            que2.pop();
            que2.push(a[N*3-1 - i]);
        }
        else T[i+1] = T[i];
    }



  ll ret = -(1LL<<60);
  for(int i = N ; i <= N * 2 ; i++){
    ret = max(ret,S[i] - T[N*3 - i]);
  }
  cout << ret << endl;
  
  return 0;
}



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

using namespace std;

int main() {
    int n;
    cin >> n;
    if (n == 2) {
        int a, b;
        cin >> a >> b;
        for (int i = 1; i <= min(a, b); ++i) {
            if (a % i == 0 && b % i == 0) {
                cout << i << '\n';
            }
        }
    } else {
        int a, b, c;
        cin >> a >> b >> c;
        for (int i = 1; i <= min(min(a, b), min(b, c)); ++i) {
            if (a % i == 0 && b % i == 0) {
                cout << i << '\n';
            } else if (a % i == 0 && b % i == 0) {
                cout << i << '\n';
            } else if (b % i == 0 && c % i == 0) {
                cout << i << '\n';
            }
        }
    }
}


Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;


int main() {
	int N,K;
	cin >> N >> K; 
	if(K==1) cout << 0 << endl;
	else cout << N-K << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int n,i,cnt=0;
scanf("%d",&n);
int A[n];
for(i=0;i<n;i++)
{
scanf("%d",&A[i]);
}

for(i=1;i<n-1;i++)
{
if((A[i-1]<A[i]&&A[i]<A[i+1])||(A[i]<A[i-1]&&A[i+1]<A[i]))
cnt++;
}
printf("%d",cnt);

return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    string s; cin >> s;
    sort(ALL(s));
    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;
typedef long double ld;

int main(void){
  int n,k; cin>>n>>k;
  ld ret;
  if( k <= n){
    ret = (ld)(n-k+1)/n;
    for(int i=1; i<k; ++i){
      ret += (ld)(pow(2, -ceil(log2((ld)k/i))) / n);
    }
  }
  else{
    ret = (ld)0.0;
    for(int i=1; i<=n; ++i){
      ret += (ld)(pow(2, -ceil(log2((ld)k/i))) / n);
    }
  }
  cout << setprecision(15) << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)

//const int NAX = (int)3e5+5;
const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    cout << n*n*n << "\n";
    return 0;
}


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

int main(){
  ll N,M,K;cin>>N>>M>>K;
  vll A(N+1),B(M+1);
  rep(i,N){cin>>A[i];}
  rep(i,M){cin>>B[i];}
  ll ans=0;
  vll acum(N+1,0),bcum(M+1,0);
  acum[0]=0;
  bcum[0]=0;
  for(int i=0;i<N;++i){
    acum[i+1] = A[i] + acum[i];
  }
  for(int i=0;i<M;++i){
    bcum[i+1] = B[i] + bcum[i];
  }
  for(ll i=0;i<N+1;++i){
    ll tmp = acum[i];
    if(acum[i]>K)continue;
    long it = distance(bcum.begin(), upper_bound(all(bcum), K-tmp));
    if(it==0) ans = max(ans, i);
    else ans = max(ans, i+it-1);
  }
  cout << ans << endl;
}

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

int N, S;
int main() {
  while (cin >> N && N > 0) {
    int sum = 0, max = 0, min = 1000;
    for (int i = 0; i < N; i++) {
      cin >> S;
      sum += S;
      if (S > max) max = S;
      if (S < min) min = S;
    }
    cout << (int)((sum-max-min)/(N-2)) << endl;
  }
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


int main(){
    double a=-1,b=-1,c;
    while(scanf("%lf",&c)!=EOF){
        if(a==-1){
            a=c;
            b=c;
        }
        if(c>a)a=c;
        if(c<b)b=c;
    }
    printf("%.10lf\n",a-b);
    return 0;
}

Measured memory_bytes: 1224
from collections import deque
H,W = map(int,input().split())
maze = []
point = -1
kabe = 0
for i in range(H):
    maze.append(input())
for i in range(H):
    for k in range(W):
        if maze[i][k] == '#':
            kabe += 1

def bfs(sy,sx,gy,gx,h,w):
    jikan = 0
    q = deque([sy*w + sx])
    saitan = [1000000]*h*w
    saitan[sy*w + sx] = 0
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    while len(q)>0 and saitan[gy*w +gx] == 1000000:
        j = q.popleft()
        y = int(j/w)
        x = j%w
        #print(saitan)
        for k in range(4):
            my = y + dy[k]
            mx = x + dx[k]
            #print(sx,sy,j,x,y,mx,my)
            if not((0 <=my <= h-1) and (0 <= mx <= w-1)):
                #print('q')
                continue
            if maze[my][mx] == '#':
                #print('b')
                continue
            if saitan[(my*w + mx)] <= saitan[y*w + x] + 1:
                #print('c')
                continue
                
            saitan[(my*w + mx)] = saitan[y*w + x] + 1
            q.append(my*w + mx)
    jikan = saitan[gy*w +gx]
    return jikan

    #print(sg_list[0][0],sg_list[0][1],sg_list[1][0],sg_list[1][1])
    #print('test')
time = bfs(0,0,H-1,W-1,H,W)
#print(time)
if time == 1000000:
    point = -1
else:
    point = point + 1 +(H * W - time - kabe-1)
print(point)


Measured memory_bytes: 3316
#include<stdio.h>
int main(){
    int m,r,f;
    for(;;){
        scanf("%d %d %d",&m,&f,&r);
        if( m == -1 && f == -1 && r == -1 ){
            break;
        }
        else if( m == -1 || f == -1 ){
            printf("F\n");
        }
        else if( m + f < 30 ){
            printf("F\n");
        }
        else if( m + f >=30 && m + f < 50 ){
            if( r >= 50 ){
                printf("C\n");
            }
            else{
                printf("D\n");
            }
        }
        else if( m + f >= 50 && m + f < 65){
            printf("C\n");
        }
        else if( m + f >= 65 && m + f < 80){
            printf("B\n");
        }
        else if( m + f >= 80 ){
            printf("A\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2140
n = int(input())
nums = list(map(int, input().split()))
cnt = 1
ans = 0
for i in range(n-1):
    if nums[i+1] == nums[i]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt // 2
        cnt = 1
if cnt > 1:
    ans += cnt // 2
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define LLI long long int

using namespace std;

int main(){
	int N,a;
	cin>>N;
	int max=0,max2=0,mi=0,mi2=0;
	for(int i=0;i<N;i++){
		cin>>a;
		if(a>max){
				max2=max;
				max=a;
				mi2=mi;
				mi=i;
		}else if(a>max2){
				max2=a;
				mi2=i;
		}
	}
	for(int i=0;i<N;i++){
		if(mi==i){
				cout<<max2<<endl;
		}else{
				cout<<max<<endl;
		}
	}


	return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>>A(N);
	for (int i = 0;i < N;++i) {
		int a;
		cin >> a;
		A[i] = make_pair(a, i + 1);
	}
	SORT(A);
	for (int i = 0;i < N;++i) {
		cout << A[i].second << "\n";
	}

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main()
{
    int N, K;

    int num = 1;

    cin >> N >> K;

    for (int i = 0; i < N; i++)
    {
        num = num < K ? num * 2 : num + K;
    }

    cout << num << endl;

    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int A, B;
  std::cin >> A >> B;

  for(int x = 1; x <= 10000; ++x) {
    if(A == x * 8 / 100 && B == x * 10 / 100) {
      std::cout << x << '\n';
      return 0;
    }
  }
  std::cout << "-1" << '\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if((a == 7 && b == 5 && c == 5)||(a == 5 && b == 7 && c == 5)||(a == 5 && b == 5 && c == 7)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
      return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k;
int p[200010],d[200010];


void solve(){
    cin >> n >> k;
    rep(i,n){
        cin >> p[i];
    }
    p[n]=-1;
    int l=0,r=0;
    while(true){
        r+=1;
        if(p[r-1]<p[r]) continue;
        while(l<r){
            d[l]=r-l;
            l+=1;
        }
        if(r==n) break;
    }
    rep(i,n){
        //cout << d[i] << endl;
    }
    set<int> s;
    Rep(i,1,k){
        s.insert(p[i]);
    }
    int ans=1;
    bool used=false;
    if (d[0]>=k) used=true;
    Rep(i,1,n-k+1){
        auto mi_itr=s.begin(),ma_itr=s.end();
        ma_itr--;
        //cout << p[i-1] << " " << *mi_itr << " " << *ma_itr << " " << p[i+k-1] << endl;
        if(p[i-1]>*mi_itr || p[i+k-1]<*ma_itr){
            if (!(used && d[i]>=k)) ans+=1;
        }
        if (d[i]>=k) used=true;
        s.erase(p[i]);
        s.insert(p[i+k-1]);
        //cout << ans << endl;
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String t = sc.next();
		String p = "";
		
		
		for(int i = 0; i < t.length(); i++) {
			if(t.charAt(i) == '?') {
				System.out.print('D');
			}else {
				System.out.print(t.charAt(i));
			}
		}
		
		System.out.println(p);
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N;

    cin >> N;
    vector<int> d(N);
    rep(i, N) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    if(d[N / 2 - 1] == d[N / 2]) {
        cout << "0" << endl;
    } else {
        cout << d[N / 2] - d[N / 2 - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 640
Sum = 0

N = int(input())

V_list = [int(i) for i in input().split()]
C_list = [int(i) for i in input().split()]

for i in range(N):
    if V_list[i]-C_list[i] >=0:
        Sum += V_list[i]-C_list[i]

print(Sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;

bool hate[10];
bool func(int i){
    if(!i) return hate[i];
    while(i){
        if(hate[i%10])return 0;
        i /= 10;
    }
    return 1;
}
int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    int n, k, tm; cin>>n>>k;
    for(int i =0; i<k; i++)cin>>tm, hate[tm] = 1;
    for(int i =n; ; i++){
        if(func(i))
            return cout<<i, 0;
    }
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int pd[100010],arr[100010];
int main()
{
    int n,m,i,ans=0,T=1;
    memset(pd,0,sizeof(pd));
    cin>>n>>m;
    
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        pd[x]++;
        pd[y]++;
    }
    for(i=1;i<=n;i++)
    {
        if(pd[i]%2==1){
            T=0;
            break;
        }
    }
    //if(m%2==0) T=1;
    if(T==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
long long a,b,x,tmp1,tmp2;
int main()
{
    scanf("%lld%lld%lld",&a,&b,&x);
    if(a % x == 0)
        tmp1 = a / x;
    else
        tmp1 = a / x + 1;
    tmp2 = b / x;
    printf("%lld",tmp2 - tmp1 + 1);
    return 0;
}

Measured memory_bytes: 128
//
//	Created by shamim_nik
//

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;

#define br printf("\n")

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

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	string str1, str2;
	cin >> str1 >> str2;
	for(int i = 0;i < str1.length(); ++i) {
        if(str1[i] != str2[i]){
            cout << "No\n";
			return 0;
        }
    }
    cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 3512
#include<iostream>
#define INF 1<<29
using namespace std;

int main(){
	int n;
	while(cin>>n && n){
		int ma=0,mi=INF;
		int sum=0;
		for(int i=0;i<n;i++){
			int s;
			cin>>s;
			mi=min(mi,s);
			ma=max(ma,s);
			sum+=s;
		}
		cout<<(sum-mi-ma)/(n-2)<<endl;
	}
}

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

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine();

            if (s.Contains("RRR"))
            {
                Console.WriteLine(3);
            }
            else if (s.Contains("RR"))
            {
                Console.WriteLine(2);
            }
            else if (s.Contains("R"))
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 25756
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    K,=pin()
    A,B=pin()
    for i in range(A,B+1):
        if i%K==0:
            print("OK")
            return
    print("NG")
#%%submit!
resolve()

Measured memory_bytes: 61696
//E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
const int mod = 1e9+7;
ll Pow(ll x,ll d){
	ll tmp = 1;
	if(!d)return 1;
	ll a = Pow(x,d/2);
	tmp = a*a%mod;
	if(d%2)tmp = tmp*x%mod;
	return tmp;
}
ll f[maxn];
int main(){
	ll ans = 0;
	int n,k;
	cin >> n >> k;
	for(int i = k;i >= 1;i--){
		ll x = k/i;
		f[i] = Pow(x,n);	
		for(int j = i+i;j <= k;j+=i)f[i] = (f[i] - f[j] + mod)%mod;
		ans = (ans + f[i]*i)%mod;
	}
	cout << ans;
	return 0;
}


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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    map<char, vector<int>> m;
    for (int i = 0; i < n; i++) {
        m[s[i]].emplace_back(i);
    }
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        auto xit = m[i+'0'].begin();
        if (xit == m[i+'0'].end()) continue;
        for (int j = 0; j < 10; j++) {
            auto yit = upper_bound(m[j+'0'].begin(), m[j+'0'].end(), *xit);
            if (yit == m[j+'0'].end()) continue;
            for (int k = 0; k < 10; k++) {
                auto zit = upper_bound(m[k+'0'].begin(), m[k+'0'].end(), *yit);
                if (zit == m[k+'0'].end()) continue;
                ans++;
            }
        }

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

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ull a,b,x;
  cin>>a>>b>>x;

  if(a==0){
    cout<<b/x+1<<endl;
    return 0;
  }

  a--;
  ll A=a/x;
  ll B=b/x;

  cout<<B-A<<endl;
  return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
lst = list(map(int, input().split()))

c = collections.Counter(lst)
p, q, r = c[1], c[2], c[3]

dp = [[[0] * (n+1) for _ in  range(n+1)]  for _ in range(n+1)]

for k in range(0, r + 1):
    for j in range(0, q + r  + 1 - k):
        for i in range(0, p + q + r + 1 - k - j):
            if i == 0 and j == 0 and k == 0:
                continue
            E = n
            if i > 0:
                E += dp[i-1][j][k] * i
            if j > 0:
                E += dp[i+1][j-1][k] * j
            if k  > 0:
                E += dp[i][j+1][k-1] * k
            dp[i][j][k] = E / (i + j + k)
print(dp[p][q][r])

Measured memory_bytes: 383184
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int a,b;
	cin >> a >> b;
	cout << max({a+b,a-b,a*b}) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std ;
using vc = vector<char> ;
using vcc = vector<vc> ;

int main(){
	int h,w ;
	cin >> h >> w ;
	vcc a(h,vc(w)) ;
	int cnt ;
	for(int i=0;i<h;i++){
		cnt = 0 ;
		for(int j=0;j<w;j++){
			cin >> a.at(i).at(j) ;
			if(a.at(i).at(j)=='#') cnt++ ;
		}
		if(cnt==0){
			for(int j=0;j<w;j++){
				a.at(i).at(j) = 'x' ;
			}
		}
	}
	for(int j=0;j<w;j++){
		cnt = 0 ;
		for(int i=0;i<h;i++){
			if(a.at(i).at(j)=='#') cnt++ ;
		}
		if(cnt==0){
			for(int i=0;i<h;i++){
				a.at(i).at(j) = 'x' ;
			}
		}
	}
	for(int i=0;i<h;i++){
		bool ok = false ;
		for(int j=0;j<w;j++){
			if(a.at(i).at(j)=='x') continue ;
			cout << a.at(i).at(j) ;
			ok = true ;
		}
		if(!ok) continue ;
		cout << endl ;
	}
}


Measured memory_bytes: 256
n = gets.to_i
array = gets.split.map(&:to_i)

negative_count = array.count { |e| e.negative? }

if negative_count.even?
  sum = array.inject(0) do |result, e|
    result + e.abs
  end

  puts sum
else
  sum = array.inject(0) do |result, e|
    result + e.abs
  end

  minus = array.min_by(&:abs).abs * 2
  puts sum - minus
end


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

signed main() {
  long long h,w,a,b;
    cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    if(i<b){
    	string s(a,'0');
    	string t(w-a,'1');
    	s+=t;
    	cout<<s<<endl;
    }
    else{
      string s(a,'1');
    	string t(w-a,'0');
    	s+=t;
    	cout<<s<<endl;
  }
  }
}


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

using namespace std;

const int MOD=1e9+7;

int n,a,b;

long long poww(long long b,long long p)
{
	if(p==0) return 1;
	if(p&1) return (b*poww(b,p-1))%MOD;
	return poww((b*b)%MOD,p/2);
}

long long nck(int k)
{
	long long ans=1;
	for(int i=n;i>n-k;i--)
		ans=(ans*i)%MOD;
	for(int i=2;i<=k;i++)
		ans=(ans*poww(i,MOD-2))%MOD;
	return ans;
}

int main()
{
	cin >> n >> a >> b;
	long long ans=(poww(2,n)-1+MOD)%MOD;
	ans-=nck(a);
	ans-=nck(b);
	ans%=MOD;
	ans+=MOD;
	ans%=MOD;
	cout << ans << endl;
}

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


struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    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(rank[x] < rank[y]){
            par[x] = y;
            sz[y] += sz[x];
        }else{
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

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

int main(){
    int N, K, L;
    cin >> N >> K >> L;
    UnionFind uf1(N), uf2(N);
    for(int i=0; i<K; i++){
        int a, b;
        cin >> a >> b;
        uf1.unite(a-1, b-1);
    }
    for(int i=0; i<L; i++){
        int a, b;
        cin >> a >> b;
        uf2.unite(a-1, b-1);
    }

    map<pair<int, int>, int> mp;
    for(int i=0; i<N; i++){
        mp[{uf1.find(i), uf2.find(i)}]++;
    }
    for(int i=0; i<N; i++){
        int ans = mp[{uf1.find(i), uf2.find(i)}];
        cout << ans << " \n"[i==N-1];
    }
}

Measured memory_bytes: 16640
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define pi pair<double, double>
#define N 1234567
int a[N];
int main() {
    int n,k;
    scanf("%d%d", &n, &k);
    for (int i=1;i<=n;i++) scanf("%d", &a[i]);

    int l=1,r=(1<<30);
    int ans=(1<<30);
    for (int _=1;_<=50;_++) {
        int mid=(l+r)/2;
        int num=0;
        for (int i=1;i<=n;i++)
            num+=(a[i]+mid-1)/mid-1;
        if (num<=k) r=mid,ans=min(ans,mid);
        else l=mid+1;
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
ll h,w;
//(xx,yy)から(xxx,yyy)までの最短路
//gridやdistの初期化に注意！
ll bfs(vector<string> &grid, long long yy, long long xx, long long yyy, long long xxx) {
    queue<pair<long long, long long>> cue;
    cue.push({yy, xx});
    vector<vector<long long>> dist(h, vector<long long>(w, -1));
    dist[yy][xx] = 0;
 
long long dy[4] = {0, 0, 1, -1};
long long dx[4] = {1, -1, 0, 0};
 
while(cue.size()){
    long long x = cue.front().second;
    long long y = cue.front().first;
    cue.pop();
    for (long long i = 0; i < 4; i++){
        long long newy = y + dy[i];
        long long newx = x + dx[i];
        if(newy>=h||newx>=w||newx<0||newy<0)
            continue;
        if(grid[newy][newx]=='#')
            continue;
        if (dist[newy][newx] != -1)
            continue;
        dist[newy][newx] = dist[y][x] + 1;
        cue.push({newy, newx});
    }
}
return dist[yyy][xxx];
}
int main(){
    cin >> h >> w;
    vector<string> grid(h);
    for (ll i = 0; i < h; i++) cin >> grid[i];
    ll ans = 0;
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w;j++){
            for (ll k = 0; k < h;k++){
                for (ll l = 0; l < w;l++){
                    if (grid[i][j] == '#' or grid[k][l] == '#') continue;
                    if (i == k and j == l) continue;
                    chmax(ans, bfs(grid, i,j,k,l));
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
	int r, d, x; cin >> r >> d >> x;
	for (int i = 1; i <= 10; i++) {
		cout << r * x - d << endl;
		x = r * x - d;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;
const int N=3e5+10;
ll a[N];
ll par[N];
ll rap[N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=0;i<3*n;i++){
        cin >> a[i];
    }
    multiset <int> s;
    for (int i=0;i<2*n;i++){
        s.insert(a[i]);
        par[i+1]=par[i]+a[i];
        if (s.size()>n){
            ll x=*s.begin();
            par[i+1]-=x;
            s.erase(s.begin());
        }
       // cout << i+1 << " " << par[i+1] << " " << s.size() << endl;
    }
    reverse(a,a+3*n);
    s.clear();
    for (int i=0;i<2*n;i++){
        a[i]=-a[i];
        s.insert(a[i]);
        rap[i+1]=rap[i]+a[i];
        if (s.size()>n){
            ll x=*s.begin();
            rap[i+1]-=x;
            s.erase(s.begin());
        }
    }
    ll ma=(ll)-1e15;
    for (int i=n;i<=2*n;i++){
        ma=max(ma,par[i]+rap[3*n-i]);
    }
    cout << ma << endl;
}




























Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define ff first
#define ss second

ll mod = 1000000007;

ll mulmod(ll a, ll b)
{
    if(b == 0)
        return 0;

    ll x = 0;
    if(b&1)
        x = a;
    ll y = mulmod(a, b/2);

    return ((y+y)%mod + x)%mod;
}

ll BigMod(ll B,ll P,ll M)
{
	ll R=1;
	while(P>0)
	{
		if(P%2==1)
		{
			R=(R*B)%M;
		}
		P/=2;
		B=(B*B)%M;
	}
	return R;
}

ll Extended_Euclidean(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;y=0;
        return a;
    }

    ll d;

    d=Extended_Euclidean(b,a%b,y,x);
    y=y-(a/b)*x;

    return d;
}
ll Inverse_Modulo(ll a,ll m)
{
    ll x,y,d;

    d=Extended_Euclidean(a,m,x,y);

    if(d==1)    return (x+m)%m; //Solution Exists
    return -1;  //No Solution
}



ll func(ll r, ll c)
{
    ll i, ret = 0, x = 1;

    ll y = 1;
    for(i = r+c+2; i >= c+2; i--)
        y = (y*i)%mod;

    for(i = 2; i <= r+1; i++)
        x = (x*i)%mod;
//        y = (y*Inverse_Modulo(i, mod))%mod;

//    cout << r << " " << c << " " << y << " " << x << " " << Inverse_Modulo(x, mod) << endl;

    return mulmod(y, Inverse_Modulo(x, mod)) - 1;
}

//void nCr(ll n, ll r)
//{
//    if(r == 0)
//        return 1;
//    if(r == 1)
//        return n%mod;
//    return (nCr(n-1, r-1) + nCr(n-1, r))%mod;
//}


int main()
{
    ll r1, r2, c1, c2, i, ans = 0, x;
    cin >> r1 >> c1 >> r2 >> c2;

    ans = (ans + func(r2, c2))%mod;
    ans = (ans - func(r2, c1-1))%mod;
    ans = (ans - func(r1-1, c2))%mod;
    ans = (ans + func(r1-1, c1-1))%mod;
    ans = (ans + mod) % mod;
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int rem=a-b;
    if(rem>c)
    {
        c=0;
    }
    else
    {
        c-=rem;
    }
    cout<<c;
    
}

Measured memory_bytes: 256
void main()
{
    long a, b, c, d;
    rdVals(a, b, c, d);

    if (abs(c- a) <= d) "Yes".writeln;
    else if (abs(b - a) <= d && abs(c - b) <= d) "Yes".writeln;
    else "No".writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
std::vector<int> v;
int main() {
	int n;
	cin >> n;
	std::vector<int> best(n,0);
	for(int i=0;i<n;i++){
	     int x;
	     cin >> x;
	     v.push_back(x);
	}
     best[0]=0;
     best[1]=abs(v[0]-v[1]);
     for(int i=2;i<n;i++){
best[i] = min({(abs(v[i]-v[i-1])+best[i-1]),(abs(v[i]-v[i-2])+best[i-2])});
     }
     // for(auto x:best){
     //      cout << x << endl;
     // }
     cout << best[n-1];
	return 0;
}


Measured memory_bytes: 4272
# include <bits/stdc++.h>
using namespace std;
struct monster{
	int health, damage;
	bool is_good(){
		return health >= damage;
	}
	bool is_bad(){
		return !is_good();
	}
	bool operator<(monster other){
		if(is_good() && other.is_bad())return true;
		if(is_bad() && other.is_good())return false;
		if(is_good() && other.is_good())return damage < other.damage;
		if(is_bad() && other.is_bad())return health > other.health;
	}
};
void solve(){
	int n;
	cin >> n;
	vector < monster > g;
	for(int i = 1; i <= n; ++i){
		string s;
		cin >> s;
		int minValue = 0, value = 0;
		for(int j = 0; j < s.size(); ++j){
			if(s[j] == ')')value --;
			if(s[j] == '(')value ++;  
			minValue = min(minValue, value);
		}
		g.push_back({value - minValue, -minValue});
	}
	sort(g.begin(), g.end());
	int curHP = 0;
	for(int i = 0; i < g.size(); ++i){
		curHP -= g[i].damage;
		if(curHP < 0){
			cout << "No\n";
			return;
		}
		curHP += g[i].health;
	}
	if(curHP){
		cout << "No\n";
		return;
	}
	cout << "Yes\n"; 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 11592
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
const long mod=1e9+7;
inline void solve(void){
  long N,K;
  in(N,K);
  long ans=0;
  up(i,K,N+1)(ans+=(-2*i*i+2*i*N+2*i+2)/2)%=mod;
  out(ans);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3640
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))


Measured memory_bytes: 22748
h, w = list(map(int, input().split()))


if not (h%3)*(w%3):
    print(0)
    exit()

def calc_T(h, w):
    bars = []
    first_cut = w//3 + w%3 - 1
    bars.append(first_cut*h)
    bars.append((h//2)*(w-first_cut))
    bars.append(h*w-sum(bars))
    return max(bars) - min(bars)

print(min(calc_T(h,w), calc_T(w,h), h, w))

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int n,k,ok=-INF,ng=INF;
vector<int> v;
priority_queue<int> pq;

signed main() {
    cin >> n >> k;
    rep(i,n) {
        int a;
        cin >> a;
        v.pb(a);
    }
    sort(all(v));
    while(abs(ok-ng) > 1) {
        int mid = (ok+ng)/2,cnt=0;
        rep(i,n) {
            if (v[i] == 0) {
                if (mid >= 0) cnt += n-i-1;
            }
            else if (v[i] < 0) {
                int tmp;
                if (mid <= 0) tmp = (mid+v[i]+1)/v[i];
                else tmp = mid/v[i];
                auto itr = lower_bound(all(v), tmp);
                cnt += max(0LL,n-max(i+1,(int)(itr-v.begin())));
            } else {
                int tmp;
                if (mid <= 0) tmp = (mid-v[i]+1)/v[i];
                else tmp = mid/v[i];
                auto itr = upper_bound(all(v), tmp);
                cnt += max(0LL,itr-v.begin()-i-1);
            }
        }
        if (cnt < k) ok = mid;
        else ng = mid;
    }
    cout << ng << endl;
}



Measured memory_bytes: 2420
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(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 REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
	string s;
	cin >> s;

	int a = 0;
	int b = 0;

	for (int i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0 && s[i] == '0')
		{
			a++;
		}
		else if (i % 2 == 1 && s[i] == '1')
		{
			a++;
		}
	}

	for (int i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0 && s[i] == '1')
		{
			b++;
		}
		else if (i % 2 == 1 && s[i] == '0')
		{
			b++;
		}
	}

	cout << min(a, b) << endl;
}



Measured memory_bytes: 3260
import java.lang.Integer.max

fun main() {
    val n = readLine()!!.toInt()
    val act = List(n) { readLine()!!.split(" ").map { it.toInt() } }

    val dp = List(n + 1) { IntArray(3) { 0 } }

    for (i in 1..n) {
        dp[i][0] = max(dp[i - 1][1] + act[i - 1][0], dp[i - 1][2] + act[i - 1][0])
        dp[i][1] = max(dp[i - 1][0] + act[i - 1][1], dp[i - 1][2] + act[i - 1][1])
        dp[i][2] = max(dp[i - 1][0] + act[i - 1][2], dp[i - 1][1] + act[i - 1][2])
    }
    println(dp[n].max())
}

Measured memory_bytes: 72300
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
int main() {
    ll n;
    cin >> n;
    vector<ll> l(n);
    REP(i, n){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    vector<ll> L;
    ll ans = 0;
    // FOR(i, 1,n){
    //     if(l[i-1] != l[i]){
    //         L.push_back(l[i-1]);
    //     }
    // }
    // if(L[L.size()-1] != l[n-1]){
    //     L.push_back(l[n-1]);
    // }
    // REP(i, L.size()){
    //     cout << L[i];
    // }
    L = l;
    ll m = L.size();
    REP(i, m-2){
        FOR(j, i+1, m-1){
            FOR(k, j + 1, m){
                if(L[k] < L[i] + L[j] && L[i] != L[j] && L[j] != L[k]){
                    ans += 1;
                }
            }
        }
    }
    
    cout << ans <<endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

typedef pair<int,int> pii;
const int N = 5e2 + 5;
int _w;


int n , dis[N][N];
bool mark[N][N];

inline bool chk( int x , int y ) {
  if( x < 1 || y < 1 || x > n || y > n ) return false;
  return true;
}

inline int ID( int x , int y ) { 
  return ( x - 1 ) * n + y;
}

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

void upd( int x , int y ) {
  static pii que[N * N];
  static int he , ta;
  --dis[x][y];
  mark[x][y] = 0;
  que[he = ta = 1] = pii( x , y );
  while( he <= ta ) {
    x = que[he].fi , y = que[he].se; ++he;
    for( int k = 0 , nx , ny ; k < 4 ; ++k )
      if( chk( nx = x + dir[0][k] , ny = y + dir[1][k] ) ) {
        if( dis[nx][ny] > dis[x][y] + mark[nx][ny] ) {
          dis[nx][ny] = dis[x][y] + mark[nx][ny];
          que[++ta] = pii( nx , ny );
        }
      }
  }
}

int main( void ) {
  _w = scanf("%d",&n);
  int m = n * n;
  for( int i = 1 ; i <= n ; ++i )
    for( int j = 1 ; j <= n ; ++j ) 
      dis[i][j] = min( min( i , j ) , min( n - i + 1 , n - j + 1 ) ) , mark[i][j] = 1;
  int x , y , id;
  long long ans = 0;
  while( m-- ) {
    _w = scanf("%d",&id);
    x = ( id - 1 ) / n + 1;
    y = ( id - 1 ) % n + 1;
    ans += dis[x][y] - 1;
    upd( x , y );
  }
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 6856
# findとrfindの使い方
s = input()
a = 0
z = 0
while True:
  a = s.find("A")
  z = s.rfind("Z")
  if s[a:z+1][0] == "A" and s[a:z+1][-1] == "Z":
    break
print(z - a + 1)

Measured memory_bytes: 3516
n, x = gets.chomp.split(' ').map{|i| i.to_i}
m = Array.new(n)
n.times do |i|
	m[i] = gets.chomp.to_i
end
min = 1000
cnt = 0
m.each do |i|
	min = (i < min) ? i : min
	x -= i
	cnt += 1
end
cnt += x / min
puts cnt


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

using namespace std;

int n,c,k,i,j,a[100005];

int main(){
	scanf("%d%d%d", &n, &c, &k);
	
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	sort(a, a + n);
	
	queue <int> t;
	
	int res = 0;
	
	for(i = 0; i < n; i++){
		while(t.size() && t.front() + k < a[i]){
			for(j = 0; j < c && t.size(); j++)
			t.pop();
			res++;
		}
		t.push(a[i]);
	}
	
	while(t.size()){
		for(j = 0; j < c && t.size(); j++)
		t.pop();
		res++;
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 640
N = int(input())
data = [0]*(N+1)
for i in range(1,N+1): data[i] = int(input())

cur = 1
cnt = 0
flag = False
while data[cur] > 0:
    if cur == 2:
        flag = True
        break
    a = data[cur]
    data[cur] = 0
    cnt += 1
    cur = a

print(cnt if flag else -1)

Measured memory_bytes: 6900