akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back

const int MN = 2e5+5;
int N, M, i, x, y, a[MN], b[MN], c[MN], f, vis[MN];
string s;
queue<int> q;
vi adj[MN];
set<pii> e;

int main(){
    cin >> N >> M >> s;
    for(i=1;i<=M;i++){
        scanf("%d%d",&x,&y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    for(i=1;i<=N;i++) c[i]=s[i-1]=='A';
    for(i=1;i<=N;i++){
        for(auto v : adj[i]){
            pii heh = make_pair(v,i);
            if(e.count(heh)) continue;
            e.insert(heh);
            if(c[i]==0) a[v]++;
            else b[v]++;
        }
    }
    for(i=1;i<=N;i++){
        if(!a[i]||!b[i]) q.push(i), vis[i]=1;
    }
    while(q.size()){
        x = q.front(); q.pop(); f++;
        for(auto v : adj[x]){
            pii kek = make_pair(v,x);
            if(!e.count(kek)) continue;
            e.erase(kek);
            if(c[x]==0) a[v]--;
            else b[v]--;
            if(!vis[v]&&(!a[v]||!b[v])){
                q.push(v);
                vis[v] = 1;
            }
        }
    }
    printf("%s\n",f!=N?"Yes":"No");
    return 0;
}


Measured memory_bytes: 31620
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,X,Y,Z = inpl()
x = sorted(inpl())
y = sorted(inpl())
c = sorted(inpl())
c = c[::-1]

i = X-a; j = Y-b
ind = 0
iok = True; jok = True
while (iok or jok) and ind < Z:
    if x[i] <= y[j]:
        if iok:
            if x[i] < c[ind]:
                x[i] = c[ind]
                ind += 1
                i += 1
                if i >= X: 
                    iok = False
                    i -= 1
            else:
                break
        else:
            if y[j] < c[ind]:
                y[j] = c[ind]
                ind += 1
                j += 1
                if j >= Y: 
                    jok = False
                    j -= 1
            else:
                break
    else:
        if jok:
            if y[j] < c[ind]:
                y[j] = c[ind]
                ind += 1
                j += 1
                if j >= Y: 
                    jok = False
                    j -= 1
            else:
                break
        else:
            if x[i] < c[ind]:
                x[i] = c[ind]
                ind += 1
                i += 1
                if i >= X: 
                    iok = False
                    i -= 1
            else:
                break
# print(x[X-a:],y[Y-b:])
print(sum(x[X-a:]) + sum(y[Y-b:]))

Measured memory_bytes: 124300
#include <cstdio>
int A, B, C, D;

void solve() {
    if (A + B > C + D) {
        printf("Left\n");
        return;
    }
    if (A + B < C + D) {
        printf("Right\n");
        return;
    }
    printf("Balanced\n");
    return;
}

int main() {
    scanf("%d %d %d %d", &A, &B, &C, &D);
    solve();
    return 0;
}

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, cmax, sum;

void read() {
  cin >> n;

  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    cmax = max(cmax, x);
    sum += x;
  }
}

void solve() {
  if (sum - cmax > cmax)
    cout << "Yes";
  else cout << "No";
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
x,y = map(int, input().split())
ans = 0

if (x==0 and y>0) or (y==0 and x<0):
  ans = abs(abs(y)-abs(x))
elif (x==0 and y<0) or (y==0 and x>0):
  ans = abs(abs(y)-abs(x))+1
else:
  ans = abs(abs(y)-abs(x))
  if x>0 and y>0:
    if x>y:
      ans += 2
  elif x>0 and y<0:
    ans += 1
  elif x<0 and y>0:
    ans += 1
  elif x<0 and y<0:
    if x>y:
      ans += 2

print(ans)




Measured memory_bytes: 3064
/**
 *  winners never quit
**/
#include <bits/stdc++.h>
using namespace std;
#define newline '\n'
#define space ' '
#define PQ priority_queue
#define VE vector
#define LL long long
#define ULL unsigned long long
#define pb push_back
#define mp make_pair
#define all(X) X.begin(), X.end()
#define II int, int
#define IS int, string
#define SI string, int
#define SS string, string
#define faster() {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
const double pi = acos(-1.0);

const int MAXN = 1;
const LL mod = 1e9 + 7;

int main()
{
  faster()
  int t, ca = 0;
  LL n, ans = 1;
  cin >> n;
  for (LL i = 2;i <= n;i++)ans = (ans*i) % mod;
  cout << ans << newline;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
  
#define AMAX 20
#define MMAX 2000
  
int n, q;
int A[AMAX+1];
int isExist[ MMAX+1 ] = {0};
 
void solve( int p, int t  )
{
	isExist[ t ] = 1;
    if( p <= n ) {
    	solve( p+1, t-A[p] );
    	solve( p+1, t  );
    }
    return ;
}
 
int main( void ) 
{
    int i;
    int num;
    int sum;
    
    scanf( "%d", &n );
    sum = 0;
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
        sum += A[i];
    }
    solve( 0, sum );
    
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( isExist[ num ] ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}

Measured memory_bytes: 588
def solve(a, b, k):
    for i in range(k):
        if i % 2 == 0:
            if a % 2 == 1:
                a -= 1
            b += a // 2
            a //= 2
        else:
            if b % 2 == 1:
                b -= 1
            a += b // 2
            b //= 2
    return "%d %d" % (a, b)

a, b, k = map(int, input().split())
print(solve(a, b, k))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;


#ifdef LOCAL
#define DEBUGMSG()                                                              \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]" ;        \
}
#define DEBUGVAR(x)                                                             \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    cerr << "([" << typeid(x).name() << "]" << #x << ")" << x << endl ;         \
}
#define DEBUGARR(l, r)                                                          \
{                                                                               \
    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \
    copy(l, r, ostream_iterator<decltype(*l)>(cerr, " "));                      \
    cerr << endl ;                                                              \
}
#else
#define DEBUGMSG()
#define DEBUGVAR(x)
#define DEBUGARR(l, r)
#endif // LOCAL

using i64 = long long;

int N;
vector <int> A, T;

int main()
{

    cin >> N ;

    i64 a, t;
    i64 ansA, ansT;

    cin >> ansA >> ansT;
    for(int i = 1; i < N; i++)
    {
        cin >> a >> t;
        if(ansA % a)
            ansA = (ansA/a + 1) * a;

        if(ansT <= ansA / a * t)
            ansT = ansA / a * t;
        else
        {
            if(ansT % t)
                ansT = (ansT/t + 1) * t;
            ansA = ansT / t * a;
        }


    }
    cout << ansA + ansT << endl ;
    return 0;
}


Measured memory_bytes: 764
import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
elif B//A > 1:
  	D = B//A-1
else:
    D = B//A
for i in range(1, C+1, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)


Measured memory_bytes: 67604
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  vector<int>sequence;
  sequence.push_back(n);
  int index = 2;
  while(true){
    if(sequence[index-2]%2==0){
        sequence.push_back(sequence[index-2]/2);
    }else{
        sequence.push_back((sequence[index-2]*3)+1);
    }
    for(int i=0;i<sequence.size()-1;i++){
            if(sequence[i]==sequence[sequence.size()-1]){
                cout<<index<<endl;
                return 0;
            }
    }
    index++;
  }
  return 0;
}


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

vector<bool> is_prime;

void eratos(int N) {
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (is_prime[i]) {
      for (int j = i * i; j <= N; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  int N;
  cin >> N;

  is_prime.resize(N + 1, true);
  eratos(N);

  map<int, int> m;
  for (int i = 2; i <= N; ++i) {
    if (is_prime[i]) {
      for (int j = i; j <= N; j *= i) {
        m[i] += N / j;
      }
    }
  }

  long long ans = 1;
  for (auto i : m) {
    ans = ans * (i.second + 1) % 1000000007;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define mod 1000000007
using namespace std;

void Onigiri()
{
  int n;
  cin>>n;
  int x=n%10;
  if(n%10==3){
    cout<<"bon";
  }
  else if(x==0||x==1||x==6||x==8)
  {
    cout<<"pon";
  }
  else cout<<"hon";
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("in", "r", stdin);freopen("out", "w", stdout);
   #endif  
 
   int t=1; 
   //cin>>t;
 
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}   

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

int main() {
  int N,D;

//   vector<vector<int>> dist(N*(N-1)));
  cin >> N>>D ;
   vector<vector<int>> data(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> data.at(i).at(j);
    }
  }
int c=0;
int dist =0;



for (int i=0;i<N;i++){
  for (int j=0;j<N;j++){
    int dist =0;
    if(i != j){
  for (int k=0;k<D;k++){
    dist += (data.at(i).at(k)-data.at(j).at(k))*(data.at(i).at(k)-data.at(j).at(k));
    //if(sqrt(dist)-sqrt(int(dist))==0){
    //  c++;
    //}
        }
  //        cout << sqrt(dist)- int(sqrt((dist))) <<endl;
        //cout << dist << endl;
        if(sqrt(dist)- int(sqrt((dist))) ==0){
          c++;
        }
      }
    }
  }

  cout << c/2<<  endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		int count = 0;
		
		for(int i = 0; i < S.length() - 1; i++) {
			if(S.charAt(i) != S.charAt(i + 1)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 25572
#include <stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    char S[4000];
    scanf("%s", S, N);
    int i, j;
    long long int countr = 0, countg = 0, countb = 0, ans = 0;
    for(i = 0; i < N; ++i){
        if(S[i] == 'R'){ ++countr; }
        else if(S[i] == 'G'){ ++countg; }
        else{ ++countb; }
    }
    ans = countr * countg * countb;
    for(i = 0; i < N-2; ++i){
        for(j = i+1; 2*j-i < N; ++j){
            if(S[i] != S[j] && S[i] != S[2*j-i] && S[j] != S[2*j-i]){ --ans; }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1740
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9+8
#define OO 1e18
#define EPS 1e-9
#define Endl '\n'
#define all(v) (v).begin(),(v).end()
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=1e5+5;
const int N=1e4+5,M=N*2;
int n;
ll a[maxn],DP[maxn][2];
ll dp(int i,bool neg){
    if(i==n)re 0;
    ll &ret=DP[i][neg];
    if(~ret)re ret;ret=LLONG_MIN;
    ret=max(ret,dp(i+1,0)+(a[i]*(neg?-1:1)));
    if(i!=n-1)ret=max(ret,dp(i+1,1)+(a[i]*((neg^1)?-1:1)));
    re ret;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%lld",a+i);
    mm(DP,-1);
    printf("%lld\n",dp(0,0));
    re 0;
}

Measured memory_bytes: 7296
if __name__ == '__main__':
    H,W=list(map(int,input().split()))
    C=[["" for i in range(W)] for j in range(H)]
    for i in range(H):
        temp=input()
        for j in range(W):
            C[i][j]=temp[j]

    ans=[["" for i in range(W)] for j in range(2*H)]
    for i in range(0,2*H,2):
        for j in range(W):
            ans[i][j]=C[i//2][j]
            ans[i+1][j]=C[i//2][j]




    for i in range(2*H):
        print(''.join(ans[i]))


Measured memory_bytes: 3316
x = list(map(int, input().split()))
if x[0] == 0:
  print("1")
elif x[1] == 0:
  print("2")
elif x[2] == 0:
  print("3")
elif x[3] == 0:
  print("4")
elif x[4] == 0:
  print("5")

Measured memory_bytes: 9024
import java.util.Arrays;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        long ans = 0;
        int cnt = 1;
        int num = a[0];
        for (int i = 1; i < n; i++) {
            if (a[i] == num) {
                cnt++;
            } else {
                if (cnt >= num)
                    ans += cnt - num;
                else
                    ans += cnt;

                num = a[i];
                cnt = 1;
            }
        }

        if (cnt >= num)
            ans += cnt - num;
        else
            ans += cnt;

        System.out.println(ans);
    }
}

Measured memory_bytes: 49348
import sys
input = sys.stdin.readline

N,W = map(int,input().split())
v = [0]
w = [0]
for _ in range(1,N+1):
    a,b = map(int,input().split())
    v.append(a)
    w.append(b)

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,W+1):
        if j >= w[i]:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]] + v[i])
        else:
            dp[i][j] = dp[i-1][j]

print (dp[N][W])


Measured memory_bytes: 25900
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll h,w;
  cin>>h>>w;
  if(h==1 || w==1) out(1);
  else if(h%2==0 || w%2==0) out(h*w/2);
  else out((h*w+1)/2);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0, n, k;
string s, t;
//cout<<<<endl;


int main()
{
	cin >> n;
	cin >> s;
	if (n % 2 == 0)
	{
		t = s.substr(n / 2, n / 2);
		if (s.substr(0,n/2) == t)
		{
			cout << "Yes" << endl; return 0;
		}
	}
		cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int M, D;
	 cin >> M >> D;
	 int ans = 0;
	for (int i = 1; i <= M; i++) {
		for (int d10 = 2; d10*10 <= D; d10++) {
			for (int d1 = 2; d1 <= 9 && d10*10+d1 <= D; d1++) {
				if (i == d1*d10) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int max[2] = {};
	for (i = 1; i <= N; i++) {
		if (A[i] > max[0]) {
			max[1] = max[0];
			max[0] = A[i];
		} else if (A[i] > max[1]) max[1] = A[i];
	}
	
	for (i = 1; i <= N; i++) {
		if (A[i] != max[0]) printf("%d\n", max[0]);
		else printf("%d\n", max[1]);
	}
	fflush(stdout);
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    
    //提出:p番目の問題で結果S
    int p[M];
    string S[M];
    for(int i = 0; i < M; ++i) cin >> p[i] >> S[i];
    
    //記録:p番目の問題で正解済か？
    //カウント対象  …0:未正解だがこの後に正解、1:正解済
    //カウント対象外…-1:この後も正解しない
    int ans[N + 1];
    for(int i = 1; i <= N; ++i){
        ans[i] = -1;
    }
    
    //正答数とペナルティ数
    int ca = 0;
    int pen = 0;
    
    //カウント対象の問題を選定
    for(int i = 0; i < M; ++i){
        if(ans[p[i]] == -1 && S[i] == "AC") ans[p[i]] = 0;
    }

    //全ての回答を確認
    for(int j = 0; j < M; ++j){
        //未正解の場合
        if(ans[p[j]] == 0){
            if(S[j] == "AC"){
                ca++;
                ans[p[j]]++;
            } else {
                pen++;
            }
        } else { //正解済の場合処理しない
            continue;
        }
    }
    cout << ca << " " << pen << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, M;
        cin >> N >> M; 
        vll c;
        for (ll i = 1; i*i <= M; ++i) {
                if (M % i == 0) {
                        c.push_back(i);
                        c.push_back(M / i);
                }
        }
        sort(all(c));
        ll ans = upper_bound(all(c), M/N) - c.begin() - 1;
        cout << c[ans] << endl;
}



Measured memory_bytes: 3604
from collections import defaultdict
import sys

N = int(input())
mod = 10**9 + 7

if N == 1:
    print(1)
    sys.exit()

dic = defaultdict(int)

for i in range(2, N+1):
    for j in range(2, i+1):
        num = 0
        while i%j == 0:
            num += 1
            i = i//j
        if num != 0:
            dic[j] += num

ans = 1
for i in dic.values():
    ans *= (i+1)
    ans %= mod
print(ans)

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

unordered_map<string, int>mp;
typedef long long lli;

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

    for(int kase = 1; kase <= n; kase++)
    {
        string s;
        cin>>s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    lli ans = 0;
    for(auto it : mp)
    {
        ans += (long long)((it.second-1ll)*(it.second));
        //cout<<it.first<<" "<<it.second<<endl;
    }
    cout<<(ans>>1)<<endl;
}



Measured memory_bytes: 10660
using System;
using System.IO;

namespace Ex160506_1{
    public class Program{
        public static void Main(string[] args){
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};

            while(true){
                var input = Console.ReadLine().Split(' ');
                var h = int.Parse(input[0]);
                var w = int.Parse(input[1]);

                if(h == 0) break;
                for(var i = 1; i <= h; i++){
                    for(var j = 1; j <= w; j++){
                        sw.Write((i + j) % 2 == 0 ? '#' : '.');
                    }
                    sw.WriteLine();
                }
                sw.WriteLine();
            }
            sw.Flush();
        }
    }
}

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

#define int long long

main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ans = i;
		}
	}
	cout << ans + n / ans - 2;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    int len1=(n-1)/2;
    int len2=(n+3)/2;
    string s1,s2;
    bool p=true;
    for(int i=0;i<n/2;i++)
    {
        if(s[i]==s[n-i-1])
        {
            continue;
        }
        else
        {
            p=false;
            break;
        }
    }
    if(p)
    {
        for(int i=0;i<len1;i++)
        {
            s1=s1+s[i];
        }
        for(int i=len2-1;i<n;i++)
        {
            s2=s2+s[i];
        }
        for(int i=0;i<s1.length()/2;i++)
        {
            if(s1[i]==s1[s1.length()-1-i])
            {
                continue;
            }
            else
            {
                p=false;
                break;
            }
        }
        for(int i=0;i<s2.length()/2;i++)
        {
            if(s2[i]==s1[s2.length()-1-i])
            {
                continue;
            }
            else
            {
                p=false;
                break;
            }
        }
        if(p)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
    else
    {
        cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 256
S = input()

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

tmp = {a: 0 for a in 'abcdefghijklmnopqrstuvwxyz'}

for x in S:
    tmp[x] += 1

tmp2 = []
if all(x == 1 for x in tmp.values()):
    for i in range(len(S)-1, 0, -1):
        tmp2.append(S[i])
        if S[i-1] < S[i]:
            tmp2 = [x for x in tmp2 if x > S[i-1]]
            print(S[:i-1]+min(tmp2))
            exit()
else:
    for k, v in tmp.items():
        if v == 0:
            tmp2.append(k)
    print(S+min(tmp2))

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

int main(){
    ll N;
    ll ans = 0;
    cin >> N;
    for (int a = 1; a <= 9; a++){
        for (int b = 1; b <= 9; b++){
            ll left = 0;
            ll right = 0;
            for (int k = 1; k <= 6; k++){
                if (k == 1 and a == b){
                    if (a <= N){
                        left += 1;
                        right += 1;
                    }
                }else if(k == 2){
                    if (10 * a + b <= N){
                        left += 1;
                    }
                    if (10 * b + a <= N){
                        right += 1;
                    }
                }else if(k == 3) {
                    for (int m = 0; m < 10; m++) {
                        if (100 * a + m * 10 + b <= N) {
                            left += 1;
                        }
                        if (100 * b + m * 10 + a <= N) {
                            right += 1;
                        }
                    }
                }else if(k == 4) {
                    for (int m = 0; m < 100; m++) {
                        if (1000 * a + m * 10 + b <= N) {
                            left += 1;
                        }
                        if (1000 * b + m * 10 + a <= N) {
                            right += 1;
                        }
                    }
                }else if(k == 5) {
                    for (int m = 0; m < 1000; m++) {
                        if (10000 * a + m * 10 + b <= N) {
                            left += 1;
                        }
                        if (10000 * b + m * 10 + a <= N) {
                            right += 1;
                        }
                    }
                }else if(k == 6) {
                    for (int m = 0; m < 10000; m++) {
                        if (100000 * a + m * 10 + b <= N) {
                            left += 1;
                        }
                        if (100000 * b + m * 10 + a <= N) {
                            right += 1;
                        }
                    }
                }
            }
            ans += left * right;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 1LL << 60;
  if(l ==0)ans = 0;
  for (ll i = l; i < min(l+2000,r); i++) {
  for (ll j = i+1; j<= min(l+2000,r); j++) { 
      mins(ans, (i * j) % 2019LL);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define nmax 100005
using namespace std;
int dp[nmax], h[nmax];

int modul(int k)
{
    if (k < 0)
        return -k;
    return k;
}

int main()
{
    int n, i, j, k;

    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> h[i];

    k = 2;
    dp[1] = 0;
    for (i = 2; i <= n; i++)
        dp[i] = 1 << 30;

    for (i = 1; i <= n; i++)
        for (j = 1; j <= k && i + j <= n; j++)
            dp[i + j] = min(dp[i + j], dp[i] + modul(h[i] - h[i + j]) );

    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,d,e;
  char c;
  cin>>c;
  a=c-48;
  cin>>c;
  b=c-48;
  cin>>c;
  d=c-48;
  cin>>c;
  e=c-48;
 // cout<<e;
  if(a<1&&b<10&&b>0){
    if(d<1&&e<10&&e>0)cout<<"AMBIGUOUS";
    else if(d==1&&e<3)cout<<"AMBIGUOUS";
    else cout<<"MMYY";
    return 0;
  }
  if(a==1&&b<3){
    if(d<1&&e<10)cout<<"AMBIGUOUS";
    else if(d==1&&e<3)cout<<"AMBIGUOUS";
    else cout<<"MMYY";
    return 0;
  }
  if(d<1&&e<10&&e>0){
    cout<<"YYMM";
    return 0;
  }
  if(d==1&&e<3){
        cout<<"YYMM";
    return 0;
  }
  cout<<"NA";
}

Measured memory_bytes: 256
ans = 0
for _ in range(5):
    i = int(input())
    if i % 10 == 0:
        ans += i
    elif ans % 10 == 0:
        ans += i
    else:
        if ans % 10 > i % 10:
            ans = (ans // 10 + 1) * 10
            ans += i
        else:
            ans += (i // 10 + 1) * 10
print(ans)

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

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
using namespace std;

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int N, K;
vector<int> x;

signed main()
{
    cin >> N >> K;
    x.resize(N);
    rep(i, N)
    {
        cin >> x[i];
    }

    auto itr = lower_bound(all(x), 0);
    int x_0 = itr - x.begin();

    //x_0-(K-1)->x_0,x_(K-2)->x_0+1,...,x_0+(K-1);
    int ans = 1e9;

    if (0 <= x_0 - K)
    {
        ans = abs(x[x_0 - K]);
    }

    rep(i, K)
    {
        if (0 <= x_0 - (K - 1 - i) && x_0 + i < N)
        {
            int dis = abs(x[x_0 - (K - 1 - i)] - x[x_0 + i]) + min(abs(x[x_0 - (K - 1 - i)]), x[x_0 + i]);
            ans = min(ans, dis);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var H, W int
	for {
		fmt.Scan(&H, &W)
		if H == 0 && W == 0 {
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				if (i+j)%2 == 0 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println("")
		}
		fmt.Println("")
	}
	return
}



Measured memory_bytes: 1140
n, x = map(int, input().split())

p = [0] * -~n
l = [0] * -~n

p[0] = 1
l[0] = 1
for i in range(1, n + 1):
    p[i] = p[i - 1] * 2 + 1
    l[i] = l[i - 1] * 2 + 3

# バーガーの長さは奇数


def rec(m, y):
    if y <= 0:
        return 0
    if m == 0:
        return 1
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)


print(rec(n, x))


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; (i) < ((int)(n)); ++(i))
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main() {
    int ans = 0;
    int N;
    cin >> N;
    rep(i, N) {
        int x = N / (i + 1);
        if(N % (i + 1) == 0)
            x--;
        ans += x;
    }

    cout << ans << endl;
}

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

int main() {
  string S; cin >> S;
  if (stoi(S.substr(0, 4)) < 2019) cout << "Heisei" << endl;
  else if (stoi(S.substr(0, 4)) > 2019) cout << "TBD" << endl;
  else if (stoi(S.substr(5, 2)) <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;++i)
#define REP(i, k, n) for(int i=k; i<=n; ++i)
#define REPR(i, k, n) for(int i=k; i>=n; --i)
#define MAX 2001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define r return
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int long long uill;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
 	long long int i;
 	int N, K, X, Y;

 	cin >> N >> K >> X >> Y;
 	long long int yen1 = 0;
 	long long int yen2 = 0;
    
    if(N<K){
 		REP(i, 1, N){
          yen1 += X;
      }
    }else if(N>K){
 		REP(i,1,N-K){
           yen2 += Y;
 		}
 		REP(i, 1, K){
          yen1 += X;
      }
    }else{
       REP(i, 1, K){
          yen1 += X;
    }
 	}

 	cout << yen2+yen1 << "\n";
    
    

 	r 0;
 }



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

vll adj[maxN];
ll dist[maxN];
ll vis[maxN];
vll order;

void dfs(ll v) {
	vis[v] = 1;
	for (auto& u : adj[v]) {
		if (!vis[u]) {
			dfs(u);
		}
	}
	order.pb(v);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	FIO
	ll n, m; cin >> n >> m;
	ll indeg[n] = {};
	ll ans = -1;
	FOR(i, m) {
		ll x, y; cin >> x >> y; --x, --y;
		adj[x].pb(y);
		indeg[y]++;
	}
	FOR(i, n) dist[i] = -1;
	for (ll i = 0; i < n; i++) {
		if (indeg[i] == 0) {
			dist[i] = 0;
		}
		if (vis[i]) continue;
		dfs(i);
	}
	reverse(all(order));
	// FOR(i, n) cout << order[i] << " "; cout << endl;
	for (ll i = 0; i < n; i++) {
		ll v = order[i];
		for (auto& j : adj[v]) {
			dist[j] = max(dist[j], dist[v] + 1);
		}
	}
	for (ll i = 0; i <= n; i++) ans = max(ans, dist[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 22752
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
	int n;
	cin >> n;
	vector<int> Adj[n];
	rep(i, n) {
		int it, k;
		cin >> it >> k;
		it--;
		rep(j, k) {
			int x;
			cin >> x;
			x--;
			Adj[it].push_back(x);
		}
	}

	vector<vector<int>> G(n, vector<int>(n, 0));
	rep(i, n){
		for(auto y : Adj[i]){
			G[i][y] = 1;
		}
	}
	rep(i, n) {
		rep(j, n - 1) cout << G[i][j] << " ";
		cout << G[i][n - 1] << endl;
	}
	return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define se second
const int N = 2e5+5;
string s;
int n,k,cst[3];/// r = 0,s = 1,p = 2
int cnt[N];
void solve(){
    cin>>n>>k;
    for(int i=0;i<3;i++)cin>>cst[i];
    cin>>s;
    for(int i=0;i<n;i++){
        if(i<k)cnt[i] = 1;
        else {
            if(s[i]==s[i-k])cnt[i] = cnt[i-k]+1;
            else cnt[i] = 1;
        }
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(cnt[i]%2){
            if(s[i]=='r')ans+=cst[2];
            if(s[i]=='s')ans+=cst[0];
            if(s[i]=='p')ans+=cst[1];
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4176
import math


def main():
    S = input()
    for i in range(len(S)-2):
        if i == 0:
            answer = math.fabs(753 - int(S[i]+S[i+1]+S[i+2]))
        else:
            if answer > math.fabs(753 - int(S[i]+S[i+1]+S[i+2])):
                answer = math.fabs(753 - int(S[i]+S[i+1]+S[i+2]))

    print(int(answer))


if __name__ == "__main__":
    main()


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

int main(void)
{
    string s;
    string k = "keyence";
    string tmp;
    size_t size;
    cin >> s;
    size = s.size();
    rep(i, size)
    {
        for (int j = i; j <= size; j++)
        {
            tmp = s.substr(0, i) + s.substr(j);
            if (k == tmp)
            {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import math

def main():

	while True:
		a,op,b = raw_input().split()
		a = int(a)
		b = int(b)
		if op == '+':
			print(a+b)
		elif op == '-':
			print(a-b)
		elif op == '*':
			print(a*b)
		elif op == '/':
			print(a/b)
		else:
			break

if __name__ == "__main__":

	main()


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



#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       {cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int>> vvi;
typedef vector<ll>     vl;
typedef vector<vector<ll>> vvl;
const int infi = numeric_limits<int>::max();
const ll infl = numeric_limits<ll>::max();

const   double         eps = 0;
const   int            ms  = 0;


int n, m;
string s;
vector<vector<int>> g; 
vi acs;
vi bcs;

vector<int> vis;
void func(int f){
    //debug(f+1)
    //debug(acs[f]);debug(bcs[f]);
    if(vis[f]==1)return;
    if(acs[f]==0 || bcs[f]==0){
        vis[f] = 1;
        vi es_ = g[f];
        g[f] = vi();
        for(auto f_:es_){
            s[f] == 'A'?acs[f_]--:bcs[f_]--;
        }

        for(auto t:es_)func(t);
    }
    
}

int main(){
    cin >> n >> m;
    cin >> s;
    g = vector<vector<int>>(n, vector<int>());
    acs = vi(n,0);
    bcs = vi(n,0);
    vis = vi(n,0);
    rep(i, m){
        //debug(i+1)debug(s[i])
        int f, t;
        cin >> f >> t;
        g[f-1].pb(t-1);
        g[t-1].pb(f-1);
    }
    rep(i, n){
        auto es = g[i];
        
        for(auto t:es){
            //debug(t)
            if(s[t]=='A')acs[i]++;
            else bcs[i]++;
        }
        //debug(i+1)debug(acs[i])debug(bcs[i])
    }
    for(int f=0; f < n; f++){
        //debug(f)
        if(g[f].size() ==0)continue;
        func(f);
    }
    int sum=0;
    for(auto es:g)if(es.size()==0)sum++;
    if(sum!=n)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 17284
#include<stdio.h>

void bubbleSort(int *,int);
#define N 100

int main(void){
  int i,n,A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  bubbleSort(&A,n);
 
  return 0;
}

void bubbleSort(int *a,int k){
  int i,j,con=0,temp;
  for(i=0;i<k-1;i++){
    for(j=k-1;j>=i+1;j--){
      if(a[j] < a[j-1]){
	temp = a[j];
	a[j]=a[j-1];
	a[j-1] = temp;
	con++;
      }    
    }
  }
  for(i=0;i<=k-2;i++) { 
   printf("%d ",a[i]);
      }
  printf("%d\n",a[k-1]);
  printf("%d\n",con);
}

Measured memory_bytes: 600
N = int(input())
h = list(map(int , input().split()))
dp = [10**9+1]*N
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])


Measured memory_bytes: 13928
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    ll n; cin >> n;
    ll a, b;
    ll ans = (1LL << 50);
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            a = i;
            b = n/i;
            ans = min(ans, a + b - 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function main(input) {
    const [a,b] = input.split(" ")
    const A = parseInt(a)
    const B = parseInt(b)
    if(A > 9 || B> 9) {
        console.log(-1)
        return
    } 

    console.log(A * B)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    string s;

    cin>>s;

    li n=s.length();

    li sum=0;

    f(i,0,n-1)
    {
        sum+=(s[i]-'0');
    }

    if(sum%9)
        cout<<"No";
    else
        cout<<"Yes";
}

int main()
{    
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

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

    return 0;
}

Measured memory_bytes: 3744
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,M = MI()
xv = [(0,0)] + [tuple(MI()) for _ in range(N)]

A = [0]*(N+1)  # 時計回りにi貫目までいけるとき、差し引き得られる最大キロカロリー
a = 0
for i in range(1,N+1):
    x,v = xv[i]
    x0,v0 = xv[i-1]
    a += v-(x-x0)
    if a > A[i-1]:
        A[i] = a
    else:
        A[i] = A[i-1]

B = [0]*(N+1)  # 時計回りにi貫目までいけるとき、差し引き得られる最大キロカロリー(最後初期位置に戻る)
b = 0
for i in range(1,N+1):
    x,v = xv[i]
    x0,v0 = xv[i-1]
    b += v-2*(x-x0)
    if b > B[i-1]:
        B[i] = b
    else:
        B[i] = B[i-1]

for i in range(1,N+1):
    x,v = xv[i]
    xv[i] = (M-x,v)
xv.sort()

C = [0]*(N+1)  # 反時計回りにi貫目までいけるとき、差し引き得られる最大キロカロリー
c = 0
for i in range(1,N+1):
    x,v = xv[i]
    x0,v0 = xv[i-1]
    c += v-(x-x0)
    if c > C[i-1]:
        C[i] = c
    else:
        C[i] = C[i-1]

D = [0]*(N+1)  # 反時計回りにi貫目までいけるとき、差し引き得られる最大キロカロリー(最後初期位置に戻る)
d = 0
for i in range(1,N+1):
    x,v = xv[i]
    x0,v0 = xv[i-1]
    d += v-2*(x-x0)
    if d > D[i-1]:
        D[i] = d
    else:
        D[i] = D[i-1]

ans = 0
for i in range(N+1):
    ans = max(ans,A[i]+D[N-i])
    ans = max(ans,C[i]+B[N-i])
print(ans)


Measured memory_bytes: 92460
import java.math.BigInteger;
import java.util.Scanner;

//A King in Hawaii
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			BigInteger b = sc.nextBigInteger();
			if(b.intValue()==-1)break;
			System.out.println(b.toString(4));
		}
	}
}

Measured memory_bytes: 32268
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL a[1005],b[1005],cna = 0,cnb = 0,tot = 1;
LL n,c[1005],cnc = 0;

int main(){
	ios::sync_with_stdio(false);
	cin >> n; n ++;
	while(n){
		c[++ cnc] = n & 1;
		n >>= 1;
	}
	
//	cout << cnc << endl;
	b[++ cnb] = 1;
	for(LL i = cnc - 1;i >= 1;i --){
		if(c[i]) a[++ cna] = ++ tot;
		if(i > 1) b[++ cnb] = ++ tot;
	}
	
	cout << tot + 100 << endl;
	for(LL i = cna;i >= 1;i --) cout << a[i] << ' ';
	for(LL i = 1;i <= cnb;i ++) cout << b[i] << ' ';
	for(LL i = 1;i <= 100;i ++) cout << i << (i == 100 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 256