akhauriyash/Code-Regression huggingface dataset:
history = set([])

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def func(n):
    if n == 1:
        return 
    l = make_divisors(n)
    for i in sorted(l[1:]):
        if i in history:
            continue
        if len(factorization(i)) > 1:
            continue
        history.add(i)
        _ = n // i
        func(_)
        break
    return

N = int(input())
if N == 0:
    print(0)
elif N == 1:
    print(0)
else:
    func(N)
    print(len(history))

Measured memory_bytes: 9644
s=input();t=input()
s=sorted(s)
t=sorted(t)
tnew=[]

for i in range(len(t)-1,-1,-1):
    #print(i)
    tnew.append(t[i])
cnt=0

if len(s)<=len(t):
    L=len(s)
else:
    L=len(t)


for i in range(L):
    if s[i]<tnew[i]:
        print('Yes')
        cnt=1
        break
    if s[i]>tnew[i]:
        print('No')
        cnt=1
        break

if cnt==0:
    if len(tnew)>len(s):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    /*auto bfs = [&](auto && self, string S) -> void{
        if(K < 0) return;
        cout << K << " " << S << endl;
        if(S == ""){
            for(char c='1';c<='9';c++){
                string tmp = S + c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    return;
                }
                self(self, tmp);
            }
        }
        else{
            for(char c='0';c<='9';c++){
                if(abs((S.back() - '0') - (c - '0')) > 1) continue;
                string tmp = S;
                tmp += c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    return;
                }
                self(self, tmp);
            }
        }
    };
    */
    queue<string> q;
    string t = "";
    q.push(t);
    while(!q.empty() && K > 0){
        string cur = q.front();
        q.pop();
        if(K == 0){
            cout << cur << endl;
            break;
        }
        if(cur == ""){
            for(char c='1';c<='9';c++){
                string tmp = cur + c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    break;
                }
                q.push(tmp);
            }
        }
        else{
            for(char c='0';c<='9';c++){
                if(abs((cur.back() - '0') - (c - '0')) > 1) continue;
                string tmp = cur;
                tmp += c;
                K--;
                if(K == 0){
                    cout << tmp << endl;
                    break;
                }
                q.push(tmp);
            }
        }
    }
    
}

Measured memory_bytes: 4864
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int DP[][] = new int[s.length()+1][t.length()+1];
        int L [][] = new int[s.length()+1][t.length()+1];
        for(int i=0;i<s.length()+1;i++) {
            Arrays.fill(DP[i],0);
            Arrays.fill(L[i],0);
        }
        for(int i=1;i<s.length()+1;i++){
            for(int j=1;j<t.length()+1;j++){
                if(s.charAt(i-1)==t.charAt(j-1)){
                    DP[i][j] = DP[i-1][j-1]+1;
                    L[i][j] = 2;
                }
                else {
                    DP[i][j] = Math.max(DP[i-1][j],DP[i][j-1]);
                    if(DP[i][j]==DP[i-1][j])L[i][j] =1;
                    else L[i][j]=3;
                }
            }
        }
        StringBuilder opt = new StringBuilder();
        int i = s.length(), j = t.length();
        for(int k=0;k<s.length()*t.length();k++){
            if(s.charAt(i-1)==t.charAt(j-1)) opt.insert(0,s.charAt(i-1));
            if(L[i][j]==1) i--;
            else if(L[i][j]==3) j--;
            else if(L[i][j]==2){
                i--;
                j--;
            }
            if(i==0||j==0) break;
        }
        System.out.println(opt);
    }
}

Measured memory_bytes: 130508
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long gcd(long a, long b) {
  while (true) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}

int main(void) {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  rep (i, N) cin >> A[i];
  long foo = A[0];
  rep (i, N) foo = gcd(foo, A[i]);
  rep (i, N) {
    if (A[i] - K >= 0 and (A[i] - K) % foo == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

void maxHeapify(vector<int>& array,int i,int n)
{
    int left_index=left(i);
    int right_index=right(i);
    int largest=0;
    if(left_index<=n && array[left_index]>array[i])
    {
        largest=left_index;
    }
    else
    {
        largest=i;
    }
    if (right_index<=n && array[right_index]>array[largest])
    {
        largest=right_index;
    }
    if(largest!=i)
    {
        int tmp=array[largest];
        array[largest]=array[i];
        array[i]=tmp;
        maxHeapify(array,largest,n);
    }
    
}

int main()
{
    int n;
    cin>>n;
    vector<int> node(n+1,0);
    for (int i = 1; i <=n; i++)cin>>node[i];
    for (int i = n/2; i >=1; i--)maxHeapify(node,i,n);
    for (int i = 1; i <=n ; i++)
    {
        cout<<" "<<node[i];
    }
    cout<<endl;

    return 0;
}



Measured memory_bytes: 4608
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    A,B = map(int,input().split())
    print(max(0,A-2*B))
if __name__ == "__main__":
    main() #endline===============================================

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

int main()
{
	int a, b;
	bool check = false;

	while (1){
		int max = 0;
		int num;

		for (int i = 0; i < 5; i++){
			cin >> a >> b;
			if (a == 0 && b == 0){
				check = true;
				break;
			}

			int sum = a + b;

			if (sum > max){
				max = sum;
				num = i;
			}
		}

		if (check){
			break;
		}

		printf("%c %d\n", num + 0x41, max);
	}

	return (0);
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N, M;
    cin >> N >> M;
    vector<i_i> ans;
    //奇数は単純
    if(N&1){
        for(int l = 1, r = N-1;l < r;l++,r--){
            ans.emplace_back(l, r);
        }
    }
    //偶数は途中で変えないといけない
    else{
        bool f = false;
        for(int l = 1,r = N; l < r; l++, r--){
            if(!f&&r-l<=N/2){
                f = true;
                r--;
            }
            ans.emplace_back(l, r);
        }
    }
    rep(i,M){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
        using namespace std;
        typedef long long ll;
        typedef long double ld;
        typedef pair<ll, ll> l_l;
        typedef pair<int , int> i_i;
        typedef vector<ll> vl;
        typedef vector<int> vi;
        typedef vector<char> vec;
        typedef vector<bool> veb;
        typedef vector<string> ves;
        typedef vector<vector<ll>> vvl;
        typedef vector<vector<int>> vvi;
        typedef vector<vector<char>> vvec;
        typedef vector<vector<bool>> vveb;
        typedef vector<vector<string>> vves;
        #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 rep2(i,n) for(int i=2;i<(int)(n);i++)
        #define repk(i,k,n) for(int i=k;i<(int)(n);i++)
        #define fs first
        #define sc second
        #define pb push_back
        #define pp pop_back
        #define all(a) a.begin(),a.end()
        #define rall(a) a.rbegin(),a.rend()
        #define maxel(a) *max_element(all(a))
        #define minel(a) *min_element(all(a))
        #define acc accumulate
        #define EPS (1e-7)
        #define INF (1e9)
        #define PI (acos(-1))
        #define mod (1000000007)
        typedef long long int64;
        //const int64 INF = 1LL << 58;
        #define dame { puts("-1"); return 0;}
        #define YES { cout << "YES" << endl; return 0; }
        #define NO { cout << "NO" << endl; return 0; }
        #define Yes { cout << "Yes" << endl; return 0; }
        #define No { cout << "No" << endl; return 0; }
        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 (a>b) { a=b; return 1; } return 0; }
        int dx[] = {0, 0, -1, 1};
        int dy[] = {1, -1, 0, 0};
         
        int main(){
        	cin.tie(0);
        	ios::sync_with_stdio(false);

	int n =0 ;
	int m =0 ;

	cin >>  n;
	cin >>  m;
	
	vi s(m);
	vi c(m);
	vi ans(n);
	int a = 0;
	rep(i,m){
	cin >> s.at(i);
	cin >> c.at(i);
	}
	rep(i,m){
	if(s.at(i) == 1 && c.at(i) == 0 && n != 1){
		dame 
	}
	}
	rep(i,m){
		repk(j,i+1,m){
			if(s.at(i) == s.at(j) && c.at(i) != c.at(j)){dame}
		}
	}
	rep(i,m){
      
		ans.at(s.at(i)-1) = c.at(i);
	}

	if(n==3){
      	
		a = ans.at(0)*100+ans.at(1)*10+ans.at(2);
      	if(ans.at(0) == 0){a += 100;}
		cout << a << endl;
	}
	if(n==2){
		a = ans.at(0)*10+ans.at(1);
        if(ans.at(0) == 0){a += 10;}
		cout << a << endl;
	}
	if(n==1){
		cout << ans.at(0) << endl;
	}
	

          	return 0;
        }

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

int main() {
  int n, a, b, point;
  cin >> n;
  a = 0;
  point = 0;
  vector<int> mochi(n);
  for (int i = 0; i < n; i++) {
    cin >> mochi.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (mochi.at(i) == mochi.at(j) && mochi.at(i) != 0) {
        a++;
        mochi.at(j) = 0;
      }
    }
  }
  cout << mochi.size() - a << endl;
}



Measured memory_bytes: 256
F = input()
o = {"R", "U","D"}
e = {"L", "U","D"}
flag = False
for i in range(len(F)):
    if( i+1) % 2 == 1:
        if F[i] not in o:
            print("No")
            flag = True
            break
    else:
        if F[i] not in e:
            print("No")
            flag = True
            break
if flag == False:
    print("Yes")

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int K;
    cin >> K;

    if (K % 2 == 0 || K % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll x = 7;
    int cnt = 1;
    while (1) {
        if (x % K == 0) {
            break;
        }
        x = (((x * 10) % K) + 7) % K;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define all(a)  a.begin(), a.end()
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define sz(a) ((int)(a.size()))
#define pb(a) push_back(a)
#define ins(a) insert(a)
#define mkpr make_pair
#define fi first
#define se second
#define newln cout<<"\n"
#define bigPrime 1000000007
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
// continue // break // greater // string // length // while

int main()
{
    fip;
    ll n,i;
    cin>>n;
    ll a[n+1];
    ll b[n];
    reptUsual(n+1)
    {
        cin>>a[i];
    }
    reptUsual(n)
        cin>>b[i];
    ll res=0;
    reptUsual(n)
    {   
        if(b[i]<=a[i])
            res+=b[i];
        else
        {
            b[i]-=a[i];
            if(b[i]<=a[i+1])
            {
                res+=a[i]+(b[i]);
                a[i+1]-=(b[i]);
            }
            else
            {
                res+=a[i]+a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout<<res;
    return 0;

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

const int inf = 1e9;
const int cont = 10e9+7;
const int mod = 1e9+7;
using namespace std;


void solve(){
  int n;
  cin>>n;
  vector<ll>v(n);
  ll sum = 0;
  for(int i =0;i<n;i++){
    cin>>v[i];
    sum += v[i];
    sum %= mod;
  }

  ll ans = 0;

  for(int i=0; i<n; i++){
    sum = (sum -v[i] + mod)%mod;
    ans += (v[i]*sum)%mod;
    ans %= mod;
  }

  cout<<ans<<endl;

}

int main(){
    solve();
    return Okay;
}



Measured memory_bytes: 4784
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int num;
vector<int> line;
int cnt;
void shellsort(int d){
	for(int i=0;i<d;++i){
		for(int j=i;j<line.size();j+=d){
			int place = j;
			while(place - d >= 0 && line[place - d] > line[place]){
				swap(line[place - d],line[place]);
				++cnt;
				place-=d;
			}
		}
	}
}
int main(){
	cin>>num;
	line.resize(num); 
	for(int i=0;i<num;++i){
		cin>>line[i];
	}
	vector<int> d;
	d.push_back(1);
	while(d.back() <= num){
		d.push_back(d.back()*4+1);
	}
	d.pop_back();
	cout<<d.size()<<endl;
	for(int i=d.size()-1;i>=0;--i){
		if(i!=d.size()-1){
			cout<<" ";
		}
		cout<<d[i];
		shellsort(d[i]);
	}
	cout<<endl;
	cout<<cnt<<endl;
	for(int i=0;i<line.size();++i){
		cout<<line[i]<<endl;
	}
	return 0;
}


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

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

using namespace std;

const int IINF = INT_MAX;

struct Data {
  int x,y,step,dir,bitmask;
  bool operator < ( const Data &data ) const {
    return step > data.step;
  }
};

int h,w,L,sx,sy,gx,gy;
char c[30][30];
int mindist[30][30][5][1<<5];

int dx[] = { 0,1,0,-1,0}; // ???,???,???,???,??´???
int dy[] = {-1,0,1, 0,0};

bool isValid(int x,int y) { return 0 <= x && x < w && 0 <= y && y < h; }

bool isValidMoveType1(int x,int y,int dir,int bitmask) {
  int cx = x, cy = y;
  rep(i,L){
    if( !isValid(cx,cy) ) return false;    
    if( c[cy][cx] == '#' ) return false;
    if( isalpha(c[cy][cx]) && islower(c[cy][cx])  && !( ( bitmask >> (c[cy][cx]-'a') ) & 1 ) ) return false;
    cx += dx[dir], cy += dy[dir];
  }
  return true;
}

void compute(){
  rep(i,h) rep(j,w) rep(l,5) rep(k,(1<<5)) mindist[i][j][l][k] = IINF;
  mindist[sy][sx][4][0] = 0;
  
  priority_queue<Data> Q;
  Q.push((Data){sx,sy,0,4,0});

  while( !Q.empty() ){

    Data data = Q.top(); Q.pop();

    if( data.x == gx && data.y == gy && data.dir == 4 ) {
      cout << data.step << endl;
      return;
    }

    if( data.dir == 4 ) {
      rep(i,4){
	int nx = data.x + dx[i], ny = data.y + dy[i];
	if( !isValidMoveType1(nx,ny,i,data.bitmask) ) continue;
	if( mindist[ny][nx][i][data.bitmask] > data.step + 1 ) {
	  mindist[ny][nx][i][data.bitmask] = data.step + 1;
	  Q.push((Data){nx,ny,data.step+1,i,data.bitmask});
	}
      }
    } else {

      // L ??????      
      // R ??????
      for(int coef=-1;coef<=1;coef+=2) {
	int nx = data.x, ny = data.y;
	if( coef == -1 ) {
	  nx += dx[data.dir] * coef, ny += dy[data.dir] * coef;
	} else {
	  nx += dx[data.dir] * coef * L, ny += dy[data.dir] * coef * L;
	}
	if( !isValid(nx,ny) ) continue;
	if( c[ny][nx] == '#' || c[ny][nx] == '^' ) continue;
	int nbitmask = data.bitmask;
	if( 'a' <= c[ny][nx] && c[ny][nx] <= 'z' ) {
	  if( !( (data.bitmask>>(c[ny][nx]-'a')) & 1 ) ) continue;
	}
	if( 'A' <= c[ny][nx] && c[ny][nx] <= 'Z' ) {
	  nbitmask |= (1<<(c[ny][nx]-'A'));
	}
	if( mindist[ny][nx][4][nbitmask] > data.step + 1 ) {
	  mindist[ny][nx][4][nbitmask] = data.step + 1;
	  Q.push((Data){nx,ny,data.step+1,4,nbitmask});
	}
      }
      
      // rolling 1
      // rolling 2
      for(int coef=-1;coef<=1;coef+=2){
	int rdir = ( data.dir + coef + 4 ) % 4;
	int nx = data.x + dx[rdir], ny = data.y + dy[rdir];
	if( !isValidMoveType1(nx,ny,data.dir,data.bitmask) ) continue;
	if( mindist[ny][nx][data.dir][data.bitmask] > data.step + 1 ) {
	  mindist[ny][nx][data.dir][data.bitmask] = data.step + 1;
	  Q.push((Data){nx,ny,data.step+1,data.dir,data.bitmask});
	}
      }
    }
  }
  puts("-1");
}

int main(){
  cin >> h >> w >> L;
  rep(i,h){
    string s;
    cin >> s;
    rep(j,w) {
      c[i][j] = s[j];
      if( c[i][j] == 'S' ) sx = j, sy = i, c[i][j] = '.';
      if( c[i][j] == 'G' ) gx = j, gy = i, c[i][j] = '.';
    }
  }
  compute();
  return 0;
}

Measured memory_bytes: 1776
n, m = gets.chomp.split.map &:to_i #nが都市、mが道路の数
ans = Array.new(n, 0)
m.times do
  a, b = gets.chomp.split.map &:to_i
  ans[a-1] += 1
  ans[b-1] += 1
end
puts ans


Measured memory_bytes: 1788
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int minScore(vector<int> &memo, vector<int> &h, int idx) {
  if (idx < 0) return INT_MAX;
  if (memo[idx] != INT_MAX) return memo[idx];
  int res = INT_MAX;
  if (idx - 1 >= 0 ) res = min(res, minScore(memo, h, idx - 1) + abs(h[idx] - h[idx - 1]));
  if (idx - 2 >= 0 ) res = min(res, minScore(memo, h, idx - 2) + abs(h[idx] - h[idx - 2]));
  memo[idx] = res;
  return res;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

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

  vector<int> memo(n, INT_MAX);
  memo[0] = 0;

  int res = minScore(memo, h, n - 1);

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 7296
h, w = map(int, input().split())
s = [input() for i in range(h)]

ans = ["" for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ans[i] += "#"
        else:
            count = 0
            if i - 1 >= 0:
                if j - 1 >= 0:
                    if s[i-1][j-1] == "#":
                        count += 1
                if s[i-1][j] == "#":
                    count += 1
                if j + 1 <= w-1:
                    if s[i-1][j+1] == "#":
                        count += 1
            if j - 1 >= 0:
                if s[i][j-1] == "#":
                    count += 1
            if j + 1 <= w-1:
                if s[i][j+1] == "#":
                    count += 1
            if i + 1 <= h-1:
                if j - 1 >= 0:
                    if s[i+1][j-1] == "#":
                        count += 1
                if s[i+1][j] == "#":
                    count += 1
                if j + 1 <= w-1:
                    if s[i+1][j+1] == "#":
                        count += 1
            ans[i] += str(count)

for i in ans:
    print(i)


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

int main(){
  int N;
  string S,T;
  cin>>N>>S;
  if(N%2!=0){
    cout<<"No"<<endl;
  }
  else{
    T=S.substr(0,N/2);
    if(T==S.substr(N/2,N/2)){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}
       
    

Measured memory_bytes: 3608
import java.io.*;
import java.util.*;
import java.math.*;


public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int x[] = {31,26,21,16,11,6,1};
		for(;;){
			int n = sc.nextInt();
		      
			if(n == 0){
				break;
			}
					
			int a[] = new int[n];
			
			for(int i = 0 ; i < n ; i++){
				a[i] = sc.nextInt();
			}
			int p = 0;
			for(int i = 0 ; i < 7;i++){
				p %= n;
				System.out.println(x[i]);
				int c = x[i]-a[p];
				System.out.println(Math.max(c, 0));
				p++;
			}
			
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
#include<stdio.h>

int main(){
        int n, i;
        scanf("%d", &n);
        int a[n];
        for(i=0; i<n; i++){
                scanf("%d", &a[i]);
        }

        long long  count=0, max=a[0];

        for(i=1; i<n; i++){
                if(max>a[i]){
                        count+=max-a[i];
                }else{
                        max=a[i];
                }
        }

        printf("%lld", count);

        return 0;
}


Measured memory_bytes: 2464
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  int c=0;
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
    c+=a[i];
  }
  if(c>=22)
    cout<<"bust";
  else cout<<"win";
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    string s; cin >> s; int n = s.size();
    rep(i, n - 1){
        if(s[i] == s[i+1]){
            outs(i+1); outs(i+2); out(""); return 0;
        }
    }
    rep(i, n - 2){
        if(s[i] == s[i+2]){
            outs(i+1); outs(i+3); out(""); return 0;
        }
    }
    out("-1 -1"); 
}

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

int main(){
    ll x,k,d;cin>>x>>k>>d;
    if(x<0)x=-x;
    ll z=x/d,ans;
    if(z>k)ans=x-k*d;
    else{
        k-=z;
        ans=x%d;
        if(k%2==0);
        else ans=d-ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 111;

int N;
vi b;
vi ans;

void printb() {
    REP (i, b.size()) {
        cout << b[i] << " ";
    }
    cout << endl;
}

int main() {
    cin >> N;
    REP (i, N) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    REP (k, N) {
        REPR (i, b.size()) {
            if (b[i] == i+1) {
                ans.push_back(i+1);
                b.erase(b.begin() + i);
                break;
            }
        }
        //printb();
    }
    if (b.size() == 0) {
        REP (i, N) {
            cout << ans[N-i-1] << endl;
        }
    } else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

typedef long long ll;
using namespace std;

int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    for (int i= 0; i < n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    ll ans = a[0];
    while(a.size() > 1){
        sort(a.begin(), a.end());

        for (int i = 0; i < n - 1; i++){
            a[i + 1] %= a[0];
            if(a[i + 1] == 0){
                a.erase(a.begin() + i + 1);
                n--;
            }
        }
    }
    cout << a[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <complex>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int p;
	int sum=0;
	vector<int>v(n);

	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	for(int i=0;i<k;i++){
		sum+=v[i];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono>
#include <climits>
#include <unordered_map>
#include <iomanip> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	auto start = high_resolution_clock::now(); 

	ll a, b;
	cin >> a >> b;
	cout << max(a - 2*b, 0LL) << endl;
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << fixed << setprecision(9) << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

ll dp[105][100007];
ll item[1000];
ll value[1000];
ll solve(ll i, ll W,ll n){



    if(i<0)return 0;



    if(dp[i][W]!=-1){
        return dp[i][W];
    }
    if(W<item[i]){
        dp[i][W]=solve(i-1,W,n);
        return dp[i][W];
    }
    ll s1;
    s1=solve(i-1,W-item[i],n)+value[i];
    ll s2=solve(i-1,W,n);
    ll ans=max(s1,s2);

    dp[i][W]=ans;
    return dp[i][W];
}
int main(){
    ll n;
    cin>>n;
    ll W;
    cin>>W;
    for(int i=0;i<105;i++){
        for(ll j=0;j<100007;j++){
            dp[i][j]=-1;
        }
    }
    for(int i=0;i<n;i++){
        ll it=0;
        cin>>it;
        ll val;
        cin>>val;
        item[i]=it;
        value[i]=val;
    }


    ll d2=solve(n-1,W,n);

    cout<<d2<<endl;

}


Measured memory_bytes: 163492
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047


void solve(){
	int n; cin >> n;
	string s; cin >> s;
	int x = 0, mx = 0;
	
	for (auto el : s){
		if (el == 'I') x++;
		else x--;
		if (x > mx) mx = x;
	}
	
	cout << mx << endl;
}

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


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

using namespace std;

int main() {
  long long n, ipt, dt, dx;
  vector<long long> t, x, y;

  cin >> n;

  t.push_back(0);
  x.push_back(0);
  y.push_back(0);

  for (long long i = 0; i < n; i++) {
    cin >> ipt;
    t.push_back(ipt);
    cin >> ipt;
    x.push_back(ipt);
    cin >> ipt;
    y.push_back(ipt);
  }

  for (long long i = 0; i < n; i++) {
    dt = abs(t[i] - t[i + 1]);
    dx = abs(x[i] - x[i + 1]) + abs(y[i] - y[i + 1]);
    if (dt % 2 != dx % 2 || dt < dx)
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 2912
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N, R;
  cin >> N >> R;
  if(N>=10) cout << R << endl;
  else cout << R+100*(10-N) << endl;
}

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

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

		 int l = s.nextInt();
		 int r = s.nextInt();
		 int d = s.nextInt();

		 int result = 0;

		 for(int i = l; i <= r; i++) {
			 if(i % d == 0) {
				 result++;
			 }
		 }

		 System.out.println(result);
	}

}

Measured memory_bytes: 27012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

#include <iostream>
using namespace std;

ll GCD(ll x, ll y) {
    if ( x == 0) {
        return y;
    } else {
        return GCD(y%x, x);
    }
}

long long num(long long n, long long c, long long d) {
    long long G = GCD(c, d);
    long long L = c / G * d;
    return n - n / c - n / d + n / L;
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << num(b, c, d) - num(a-1, c, d) << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	double cosA[1001], A[1001];
	int i, n;

	for(i=2; i<=1000; i++)
		cosA[i] = sqrt((double)(i-1)/i);

	for(i=2; i<=1000; i++)
		A[i] = acos(cosA[i]);

	for(i=3; i<=1000; i++)
		A[i] = A[i-1] + A[i];

	while(1){

		scanf("%d", &n);
		if(n == -1)
			break;

		printf("%.2f\n%.2f\n", sqrt(n)*cos(A[n]), sqrt(n)*sin(A[n]));

	}

	return 0;

}

Measured memory_bytes: 728
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 105;

int n;
int a[maxn];

int dp[maxn][15];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

void solve()
{
    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -1);
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 10; ++j)
        {
            if(dp[i][j] == -1) continue;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            int nj = (j + a[i + 1]) % 10;
            dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + a[i + 1]);
        }
    int ans = 0;
    for(int j = 1; j < 10; ++j)
        ans = max(ans, dp[n][j]);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 256
x, y = map(int, input().split())
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

group = [g1, g2, g3]

flag = False
for g in group:
    if x in g and y in g:
        print("Yes")
        flag = True

if flag == False:
    print("No")

Measured memory_bytes: 3064
def bubbleSort(a,n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if a[j-1][1] > a[j][1]: #Sort by card number
                a[j-1], a[j] = a[j], a[j-1]
    print(' '.join(a))

def selectionSort(a,n):
    for i in range(n):
        minj = i
        for j in range(i,n):
            if a[j][1] < a[minj][1]: #Sort by card number
                minj = j
        if minj != i:
            a[i],a[minj] = a[minj],a[i]
    a = [str(s) for s in a]
    print(' '.join(a))

def isStable(a, a2):
    """
    :param a: Stable-sorted list (Bubble sort)
    :param a2: List to check if isStable
    :return: Boolean
    """
    if a == a2:
        return True
    else:
        return False

n = int(input())
a = list(input().split())
a2 = a[::]

bubbleSort(a,n)
print('Stable')
selectionSort(a2,n)
print('Stable' if isStable(a, a2) else 'Not stable')


Measured memory_bytes: 5624
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
ints = lambda: list(map(int, input().split()))
mod = 10**9+7
n,k = ints()
def f(x,N):
    a = 2*x**2
    c = 3*N
    b = c*x
    return int(x*(-a+b+c+8)/6)

print((f(n+1,n)-f(k-1,n))%mod)

Measured memory_bytes: 9464
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <stdlib.h>
#include <functional>
#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
using namespace std;

int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	printf("%d\n", (n - 1)*(m - 1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;
    int count = 0, sum = 1;
    while(sum < B) {
    	sum += A - 1;
    	count++;
	}
	cout << count << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int dp[100000][3],n;
  cin >> n;
  for(int i=0; i<n; i++) {
    for(int j=0; j<3; j++) {
      int k;
      cin >> k;
      dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+k;
    }
  }
  cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(4100000)

def dfs(x, y):
  atlas[y][x] = 0
  for horizonal in range(-1, 2):
    for vertical in range(-1, 2):
      nx = x + horizonal
      ny = y + vertical
      if nx < 0 or w <= nx or ny < 0 or h <= ny:
        continue
      if atlas[ny][nx] == 0:
        continue
      dfs(nx, ny)

while True:
  count = 0
  w, h = map(int, input().split())
  atlas = []
  if w == 0 and h == 0:
    break
  for _ in range(h):
    atlas.append(list(map(int, input().split())))
  for x in range(w):
    for y in range(h):
      if atlas[y][x] == 0:
        continue
      dfs(x, y)
      count += 1
  print(count)


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	ll ans =0;
	for (int i = 1; i <= N;i++) {
		ans += (N / i);
		if (N%i==0) {
			ans--;
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    fast

    int n;
    cin>>n;
    int maxi=0;int secmaxi=0;
    int maxiindex=-1;
    int temp;
    vector<int>arr(n,0);
    for(int i=0;i<n;i++){
        cin>>temp;
        arr[i]=temp;
        if(temp<secmaxi)
            continue;
        if(temp>maxi){
            secmaxi=maxi;
            maxi=temp;
            maxiindex=i;
        }
        else if(temp>secmaxi && temp<=maxi)
        {
            secmaxi=temp;

        }

    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(arr[i]==maxi)cnt++;
    }
    if(cnt>=2)
        for(int i=0;i<n;i++)cout<<maxi<<endl;
    else{
    for(int i=0;i<n;i++){
        if(arr[i]==maxi)
            cout<<secmaxi<<endl;
        else
            cout<<maxi<<endl;

    }
    }





	return 0;
}


/*
ll  modularExponentiation(ll x,ll n,ll M)
{

    ll result=1;

    while(n>0)
    {

	if(n%2==1)

 result=(result*x)%M;

  x=(x*x)%M;

  n=n/2;

}

  return result;
}



*/


Measured memory_bytes: 2432
import itertools
N,K=map(int,input().split())
X=((N-1)*(N-2))//2

if K>X:
  print(-1)
else:
  print(N-1+X-K)
  k=X-K
  
  for i in range(2,N+1):
    print(1,i)
  for a,b in itertools.combinations(range(2,N+1),2):
    if not k:
      break
    print(a,b)
    k-=1

Measured memory_bytes: 43120
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i]+l[j])
        cnt += x-j-1

print(cnt)

Measured memory_bytes: 9336
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int a[10]; fill(a, a + 10, 0);
    int b;
    for(int i=0; i<3; i++){
        cin >> b;
        a[b]++;
    }
    string ans = "No";
    for(int i=0; i<10; i++){
        if(a[i] == 2) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a, int b)
{
    if(a % b == 0){
        return b;
    } else {
        return gcd(b, a % b);
    }
}
int main()
{
    int a, b, c;
    scanf("%d %d", &a, &b);
    if(a > b){
        c = gcd(a, b);
    } else {
        c = gcd(b, a);
    }
    printf("%d\n", c);
    return 0;
}

Measured memory_bytes: 592
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc043/tasks/abc043_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s):
    ans = []

    for c in s:
        if c == 'B':
            if len(ans) > 0:
                ans.pop()
        else:
            ans.append(c)
    return ans


def main(args):
    s = input().strip()
    ans = solve(s)
    print(*ans, sep='')


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3064
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int main(){

    int a, b, c;

    cin >> a >> b >> c;

    if ((10 * b + c) % 4 == 0) printf("YES\n");
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N, Y;


void solve()
{
	int a, b = 0, c;
	Y /= 1000;
	int tmp = Y - N;
	for (; tmp % 9 != 0 && tmp >= 0; tmp -= 4, b++);
	a = tmp / 9;
	c = N - a - b;
	if (a >= 0 && a + b <= N && tmp >= 0) cout << a << " " << b << " " << c << endl;
	else cout << "-1 -1 -1" << endl;
}

int main()
{
	cin >> N >> Y;
	solve();
	return 0;
}

Measured memory_bytes: 256