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

int main() {
  int N;
  cin >> N;
  int j=0;

  // ここにプログラムを追記
  for (int i=0; i<N; ++i) {
    int A,B;
    cin >> A >> B;
    j += B-A+1;
}
  cout << j << endl;
}


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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in(),k=in(),q=in(),pt[n],a;
    for (int i=0;i<n;i++) pt[i]=k-q;
    for (int i=0;i<q;i++) {
        cin >> a;
        pt[a-1]++;
    }
    for (int i=0;i<n;i++){
        if (pt[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

#define ll long long

using namespace std;


int W,H;

char r[1000][1000];

int sh,sw;
int bnum=0;

int solve(int i,int j){
    int ans=0;

    if(i <0 || H <= i || j < 0 || W <= j)
        return 0;
    if(r[i][j] == '#'){
        return 0;
    }
    ans = 1;
    r[i][j] = '#';
    ans += solve(i-1,j);
    ans += solve(i+1,j);
    ans += solve(i,j-1);
    ans += solve(i,j+1);

    return ans;
}


int main(){

    while(1){
        scanf("%d %d",&W,&H);
        if(W == 0 && H == 0) break;

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin >> r[i][j];
                if(r[i][j] == '@'){
                    sh = i;
                    sw = j;
                    r[i][j] = '.';
                }
            }
        }
        cout << solve(sh,sw) << endl;
    }

}


Measured memory_bytes: 3168
#include<iostream>
#include<cmath>

using namespace std;

static const long double EPS = 1e-10;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2; // p2→p0→p1
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point{
    public: 
    long double x,y;
    Point(long double x = 0.0, long double y = 0.0): x(x), y(y) {}
    Point operator + (Point p) const { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) const { return Point(x-p.x, y-p.y); }
    Point operator * (long double a) const { return Point(x*a, y*a); }
    Point operator / (long double a) const { return Point(x/a, y/a); }
    bool operator < (const Point &p) const { return (x != p.x ? x < p.x : y < p.y); }
    bool operator == (const Point &p) const { return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS; }
    long double abs() const { return sqrt(norm()); }
    long double norm() const { return x*x + y*y; }
    long double dot(Point p) const { return x*p.x + y*p.y; }
    long double cross(Point p) const { return x*p.y - y*p.x; }
};


int ccw(Point p0, Point p1, Point p2){
    Point a = p1 - p0;
    Point b = p2 - p0;
    if(a.cross(b) > EPS) return COUNTER_CLOCKWISE;
    if(a.cross(b) < -EPS) return CLOCKWISE;
    if(a.dot(b) < -EPS) return ONLINE_BACK;
    if(a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

int main(){
    int x1,y1,x2,y2, n;
    cin >> x1 >> y1 >> x2 >> y2;
    Point p = Point(x1, y1), q = Point(x2, y2);
    cin >> n;
    int x,y;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        switch(ccw(p, q, Point(x, y))){
            case COUNTER_CLOCKWISE:
                cout << "COUNTER_CLOCKWISE";
                break;
            case CLOCKWISE:
                cout << "CLOCKWISE";
                break;
            case ONLINE_BACK:
                cout << "ONLINE_BACK";
                break;
            case ONLINE_FRONT:
                cout << "ONLINE_FRONT";
                break;
            default:
                cout << "ON_SEGMENT";
                break;
        };
        cout << "\n";
    }
}




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

int days[20];

bool isLeap(int year){
	if(year % 4 != 0)return false;
	if(year % 400 != 0 && year % 100 == 0)return false;
	return true;
}

int calc(int y, int m, int d){
	days[2] = isLeap(y) ? 29 : 28;
	int sum = 0;
	for(int i=1;i<m;i++)sum += days[i];
	sum += d;
	return sum;
}

int cereal(int y, int m, int d){
	if(y == 0)return calc(y, m, d);
	int sy = y - 1;
	int ly = sy / 4 - sy / 100 + sy / 400 + 1;
	int ny = y - ly;
	int sum = ly * 366 + ny * 365 + calc(y, m, d);
	return sum;
}

int main(){
	for(int i=1;i<=12;i++)days[i] = 31;
	days[4] = days[6] = days[9] = days[11] = 30;

	int y1, m1, d1, y2, m2, d2;
	while(cin >>  y1 >> m1 >> d1 >> y2 >> m2 >> d2){
		if(y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0){
			break;
		}
		cout << cereal(y2, m2, d2) - cereal(y1, m1, d1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
{-# LANGUAGE BangPatterns #-}
import           Debug.Trace
main=getLine>>=print.solve
solve :: String -> Int
solve cs = minimum $ map step ['a'..'z']
  where
    step c = go 0 cs
      where
        go !res xs
          | all (c==) xs = res
          | otherwise = go (res + 1) . init $ f xs
        f (x:y:xs)
          | x == c || y == c = c : f (y:xs)
          | otherwise = x : f (y:xs)
        f xs = xs


Measured memory_bytes: 1020
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		List<Integer> numList = new ArrayList();

		numList.add(Integer.parseInt(sc.next()));
		int count = 0;
		while(true) {
			count++;
			if(count == a) break;
			numList.add(Integer.parseInt(sc.next()));
		}
		int count2 = 0;
		LABEL1: while(true) {
			for(int i = 0; i <= numList.size() - 1; i++) {
				if(numList.get(i) % 2 == 0) {
					numList.set(i, numList.get(i)/2);
				} else {
					break LABEL1;
				}
			}
			count2++;
		}
		System.out.println(count2);


	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long s;
	cin >> s;
	int ans=1000;
	while(s/100>0) {
		int a = s % 1000;
		ans = min(ans, abs(a - 753));
		s /= 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
read = input 
rn = lambda :map(int, read().split())
m,k = rn()
import math
N = 2**(m) - 1 # 0~N
r = [i for i in range(N+1)] # 0~N
if k > N:
    print(-1)
# elif N == 1 and k == 0:
#     print(0, 0)
elif N == 1 and k == 1:
    print('-1')
elif k ==  0:
    for i in r:
        print(i, end=' ')
    r.reverse()
    for i in r:
        print(i, end=' ')
elif N == 2 and k == 1:
    print(-1)
else:
    for i in r:
        if i == k:continue
        print(i, end=' ')
    print(k, end=' ')
    r.reverse()
    for i in r:
        if i == k:continue
        print(i, end=' ')
    print(k, end=' ')
    

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s= sc.next().toCharArray();
		Arrays.sort(s);
		if (s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23252
// 1_abc135_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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 SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << (a + b) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T> void print(T a, T b) { 
    for (T i = a; i != b; ++i) { if (i != a) { cout << " "; } cout << *i; } cout << endl; 
}
    


const int MAX = 100100;

int t;
int n, k;
int x[MAX];
int y[MAX];


int main() {
    cin >> t;
    for (int id = 0; id < t; ++id) {
        cin >> n >> k;
        for (int i = 0; i < n; ++i) cin >> x[i];
        
        sort(x, x+n);
        for (int i = 0; i < n; ++i) y[i] = x[i+1] - x[i];
        
        sort(y, y+(n-1), greater<int>());
        ll deg = 0;
        for (int i = 0; i < min(k-1,n-1); ++i) deg += y[i];
        
//        
//        print(x, x+n);
//        print(y, y+(n-1));
//        COUT(deg);
//        cout << endl;
        
        cout << x[n-1] - x[0] - deg << endl;
    }
        
    
    return 0;
}


Measured memory_bytes: 1960
using System;

namespace B___Papers__Please
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var input = Console.ReadLine ().Split (' ');
            foreach (var p in input)
            {
                var x = int.Parse (p);
                if (x % 2 == 0 && (x % 3 != 0 && x % 5 != 0))
                {
                    Console.WriteLine ("DENIED");
                    return;
                }
            }
            Console.WriteLine ("APPROVED");
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	
	string s[5];
	cin >> s[0] >> s[1] >> s[2];
	if (s[0].back() == s[1][0] && s[1].back() == s[2][0])cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    int ct = 0;
    int tmp = 0;
    rep(i,S.size()){
        char t = S[i];
        if(t == 'A' || t == 'C' || t == 'G' || t == 'T'){
            tmp++;
        }
        else{
            tmp = 0;
        }
        ct = max(ct,tmp);
    }

    cout << ct << endl;
}


Measured memory_bytes: 256
num = list(map(int,input().split()))
lp = 0
while lp < len(num)-1:
    rp = len(num)-1
    while rp > lp:
        if num[rp] < num[rp-1]:
            x = num[rp]
            num[rp] = num[rp-1]
            num[rp-1] = x
        rp -= 1
    lp += 1
print(num[0]+num[1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0);
const int32_t mod = 1e9+7;
const int32_t maxn=2e5+5;
int inf=1e18;

bool go(string s){
    int res=0;
    for(char c:s){
        res+=c-'0';
        res%=9;
    }
    return res==0;
}

void solve(){
    string s;
    cin>>s;
    cout<<(go(s)?"Yes":"No");
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>

using namespace std;

int main()
{
	int i, k, n, x=1;
	int result = 0;
	int* a;
	cin >> n;
	a = new int[n];
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	for (i = 0; i < n; i++) {
		if (a[i] == x) {
			x++;
		}
		else {
			result++;
		}
	}
	if (result == n) result = -1;
	cout << result;
	delete[] a;
	return 0;
}

Measured memory_bytes: 1024
INF = 1001001001
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [INF] * (H+1)
dp[0] = 0
for i in range(N):
    for j in range(H+1):
        if j>ab[i][0]:
            dp[j] = min(dp[j], dp[j-ab[i][0]] + ab[i][1])
        else:
            dp[j] = min(dp[j], ab[i][1])
print(dp[H])


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

LL a[mx5];

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

    LL cnt = 0, ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];

        cnt += a[i];
        if(i % 2){
            if(cnt >= 0)
                ans += cnt + 1, cnt = -1;
        }
        else{
            if(cnt <= 0)
                ans -= cnt - 1, cnt = 1;
        }
    }

    LL a2 = 0;
    cnt = 0;
    for(int i = 0; i < n; i++){
        cnt += a[i];
        if(i % 2 == 0){
            if(cnt >= 0)
                a2 += cnt + 1, cnt = -1;
        }
        else{
            if(cnt <= 0)
                a2 -= cnt - 1, cnt = 1;
        }
    }

    cout << min(ans, a2) << '\n';
    return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
int main() {
        string s,t;
        cin >> s >> t;
        // sを辞書順で一番小さいのに
        // tを辞書順で一番大きいのに
        for(int i =  0; i < s.length(); i++){
            for(int j = i+1; j < s.length(); j++){
                if(s[i] > s[j]) {
                    char temp = s[i];
                    s[i] = s[j]; s[j] = temp;
                } 
            }
        } 
        for(int i =  0; i < t.length(); i++){
            for(int j = i+1; j < t.length(); j++){
                if(t[i] < t[j]) {
                    char temp = t[i];
                    t[i] = t[j]; t[j] = temp;
                } 
            }
        } 
        if(s < t) cout << "Yes" << endl;
        else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    // Here your code !
    int a, b;
    cin >> a >> b ;
    cout << a/b <<" " << a%b << " ";
    printf("%9f", a*1.0/b*1.0);
    return 0;
}

Measured memory_bytes: 3232
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيم

#include <bits/stdc++.h>
using namespace std;

typedef  long long i64;
#define el cout << '\n';
#define lcm(a, b) a / __gcd(a, b) * b
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define max(a,b,c) max(max(a,b),max(a,c))
#define gcd(a,b,c) __gcd(__gcd(a,b),__gcd(a,c))

template <class... Args>auto &see(const Args &... args){return ((cerr << " " << args), ...) << '\n';}
#define bug(...)   cerr << "[ " #__VA_ARGS__ " ] = "; see(__VA_ARGS__) << '\n';



void solve(){
    
    int k ; cin >> k ; i64 s = 0;
  
    for (int i = 1; i <= k; i++)
       for(int j = 1 ; j <=k ; j++)
         for(int r = 1 ; r <= k ; r++)
             s += (i64)gcd(i,j,r);
     

    cout << s ; el
  
}






int main()
{
  int t = 1 ; 
  
  while(t--)solve() ;

}
                            

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

int main(void){
	int x,h;
	while(cin >> x >> h,x|h){
		double ans=1.0*x*x;
		double hypo=sqrt(0.25*x*x+1.0*h*h);
		ans+=2.0*x*hypo;
		cout.precision(10);
		cout << fixed << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//ABC129 E

const int MAX = 510000;
const ll MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(void) {
	string l;
	cin >> l;
	COMinit();
	vector<ll> memo3(l.size() + 1);
	vector<ll> memo2(l.size() + 1);
	memo3[0] = 1;
	memo2[0] = 1;
	rep(1, l.size() + 1) {
		memo3[i] = memo3[i - 1] * 3 % MOD;
		memo2[i] = memo2[i - 1] * 2 % MOD;
	}

	ll all = memo3[l.size()];
	ll size = l.size();
	int index = 1;
	ll rm = 0;
	ll count1 = 0;
	

	rep(0, size) {
		if (l[i] == '0') {
			rm += 2 * memo2[count1] * memo3[size - i - 1] % MOD;
			rm %= MOD;
		}
		else count1++;
	}
	cout << (all - rm + MOD) % MOD  << endl;
}


Measured memory_bytes: 13952
#include<iostream>
#include<vector>
using namespace std;
int n;
vector<int> tree[100005];
int succ[100005]={};
int depth;
bool haveN[100005];

int dfs(int v,int p,int d){
	if(v==n) depth=d;
	if(tree[v].size()==1 && tree[v][0]==p) return succ[v]=1;
	for(int i=0;i<tree[v].size();i++){
		if(tree[v][i]==p) continue;
		succ[v]+=dfs(tree[v][i],v,d+1);
		if(haveN[tree[v][i]]) haveN[v]=true;
	}
	return ++succ[v];
}
int dfs2(int v,int p,int d){
	if(d==depth/2+1) {
		return succ[v];
	}
	for(int i=0;i<tree[v].size();i++){
		if(tree[v][i]==p) continue;
		if(haveN[tree[v][i]]) return dfs2(tree[v][i],v,d+1);
	}
}

int main(){
	cin >> n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	haveN[n]=true;
	succ[1]=dfs(1,-1,0);		
	bool ans = n-dfs2(1,-1,0)>n/2?true:false;
	if(ans) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y) 
{ 
    ll res = 1;     x = x;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x); 
        y = y>>1LL; 
        x = (x*x);   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll x;cin>>x;
    vector<ll> cubes(2001);
    for(ll i=-1000;i<=1000;i++)
    {
        cubes[i+1000]=powmp(i,5);
    }
    f(i,0,2001)
    {
        auto it=LB(cubes.begin(),cubes.end(),x+cubes[i]);
        if(*it==x+cubes[i])
        {
            cout<<it-cubes.begin()-1000<<" "<<i-1000<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    vector<int> v(n+1);
    rep(i, n) {
        int a; cin >> a;
        v[a] = i + 1;
    }
    rep1(i, n) cout << v[i] << " ";
}


Measured memory_bytes: 3784
import sys

input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        uf.union(A-1, B-1)
    roots = uf.roots()
    cnt = []
    for r in roots:
        cnt.append(uf.size(r))
    cnt.sort(reverse=True)
    ans = cnt[0]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	double w,h,v,t,x,y,p,q;
	cin >> w >> h >> v >> t >> x >> y >> p >> q;
	vector<double> vec;
	const int lim = 1000100;
	for(int i = -lim;i <= lim;i++){
		if(i % 2) vec.push_back(h * (i + 1) - q);
		else vec.push_back(h * i + q);
	}
	sort(all(vec));
	int ans = 0;
	for(int i = -lim;i <= lim;i++){
		double a;
		if(i % 2) a = w * (i + 1) - p;
		else a = w * i + p;
		if(v * v * t * t - (a - x) * (a - x) < 0) continue;
		double b = sqrt(v * v * t * t - (a - x) * (a - x));
		ans += upper_bound(all(vec),b + y + EPS) - lower_bound(all(vec),-b + y - EPS);
	}
	cout << ans << endl;
}


Measured memory_bytes: 19512
N = int(input())
A = list(map(int, input().split()))

cnt = 0
cnt_li = []
for i in range(N):
    cnt = 0
    while A[i]%2 == 0:
        cnt += 1
        A[i] = A[i] / 2
    cnt_li.append(cnt)
print(min(cnt_li))



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

int keta(int N){
    int count = 1;
    while(N/10>=1){
        count++;
        N/=10;
    }
    return count;
}

int main(){
    int N;
    cin >> N;
    int count = 0;
    if(keta(N)%2==0){
        for(int i=0;i<keta(N)/2;i++){
            count += 9*pow(10,2*i);
        }
    }
    else{
        for(int i;i<(keta(N)-1)/2;i++){
            count += 9*pow(10,2*i);
        }
        count += N - pow(10,keta(N)-1) + 1;
    }
    cout << count << endl;
}


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

string s;

int m=1e9+7,dp[10009][2][100],p,d;


int dfs(int idx,int z,bool tight){
  if(idx==s.size())return !z;
  int &res=dp[idx][tight][z];
  if(~res)return res;
  res=0;
  int r=(tight?9:s[idx]-48);
  for(int i=0;i<=r;i++){
    res+=dfs(idx+1,(z+i)%d,tight||i<r);
    res%=m;
  }
  return res;
}

int main(){
  memset(dp,-1,sizeof dp);
  cin>>s>>d;
  cout<<(dfs(0,0,0)-1+m)%m<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


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

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

const long long INF = 1LL << 60;

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

  if(n%1000 == 0){
    cout << 0 << endl;
    return 0;
  }

  cout <<  1000*(n/1000+1) - n << endl;

  return 0;
}


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

int main()
{
	int n,j;
	scanf("%d",&n);
	int a[n],an[n];
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	for(int i=0; i<n; i++){
		j = a[i];
		an[j-1] = i+1;
	}
	printf("%d",an[0]);
	for(int i=1; i<n; i++)printf(" %d",an[i]);
	printf("\n");
	return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a;
  double b;
  cin >> a >> b;
  ll c = round(b * 100.0);
  cout << a * c / 100LL << '\n';
  return 0;
}


Measured memory_bytes: 3764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
long long f(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return -b; // 1つ前の f で余分な b が足されている
  return 2 * (b / a) * a + f(a, b % a); // a と b の大小関係が変わる
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  long long n, x; cin >> n >> x;
  cout << n + f(n - x, x) << '\n';
  return 0;
}


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

int main(){
    int a,b,c;cin>>a>>b>>c;
    if (c>=a&&b>=c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
	return 0;
}

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

    long result = modPow(2, n) - 1;
    long fa = 1, fb = 1;

    foreach (i; 0 .. b)
    {
        if(i < a) fa = fa * (n - i) % mod;
        fb = fb * (n - i) % mod;
    }

    long[] finv = new long[b+1];
    long[] inv = new long[b+1];
    finv[0] = 1, finv[1] = 1;
    inv[1] = 1;
    foreach (i; 2 .. b+1) {
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }

    long ca = fa * finv[a] % mod;
    long cb = fb * finv[b] % mod;

    result = (result + mod - ca) % mod;
    result = (result + mod - cb) % mod;

    result.writeln;
}

long modPow(long x, long y)
{
    long result = 1;
    while (y > 0)
    {
        if (y & 1) result = result * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return result;
}

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

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int w, cut = 1;
    while(cin >> w, w){
        int n;
        cin >> n;
        vector<int> dp(w+1, -INF<int>);
        dp[0] = 0;
        for (int i = 0; i < n; ++i) {
            int a, b;
            scanf("%d,%d", &a, &b);
            for (int j = w-b; j >= 0; --j) {
                dp[j+b] = max(dp[j+b], dp[j]+a);
            }
        }
        auto ans = max_element(dp.begin(),dp.end());
        printf("Case %d:\n%d\n%ld\n", cut++, *ans, ans-dp.begin());
    }
    return 0;
}


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


def main():
    n = int(input())
    ans = float('inf')

    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            ans = min(ans, (i - 1) + (n // i - 1))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 1e9;
    for(int i = -100; i <= 100; i++){
        int score = 0;
        rep(j,n){
            score += (a[j]-i)*(a[j]-i);
        }
        chmin(ans, score);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int used[2][100010] = {0};
int color[2] = {0};
vector<int> G[100010];

void dfs(int v, int c){
    used[c][v]++;
    color[c]++;
    for(auto x: G[v]){
        if(used[c ^ 1][x]) continue;
        dfs(x, c^1);
    }
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(0, 0);
    ll ans = 0;

    if(used[0][0] * used[1][0]) {
        cout << (ll)n * (n - 1) / 2 - m << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        int b = used[0][i], w = used[1][i];
        ans += b * (color[1] - G[i].size()) + w * (color[0] - G[i].size());
    }
    ans /= 2;

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


Measured memory_bytes: 8448
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            Console.WriteLine((S[2] == S[3] && S[4] == S[5]) ? "Yes" : "No");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 26560
#include<bits/stdc++.h>
using namespace std;
int n;
double m;
const int mmax=1e5+8;
int a[mmax];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	cout<<a[n]<<' ';
	m=a[n]/2.0;
	double minn=fabs(a[1]-m);
	int t=1;
	for(int i=2;i<n;i++){
		if(minn>fabs(a[i]-m)){
			minn=fabs(a[i]-m);
			t=i;
		}
	}	
	cout<<a[t];
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
int n;
int dp[2000200];
int suf[2000200];
int main()
{
	scanf("%d",&n);
	for(int i=n+1;i<=n*2+10;++i)dp[i]=1;
	for(int i=n*2+10;i>n;--i)suf[i]=suf[i+1]+1;
	dp[n]=n;suf[n]=suf[n+1]+n;
	for(int i=n-1;i;--i)
	{
		dp[i]=add(dp[i],dp[i+1]);
//		cout<<dp[i]<<endl;
		dp[i]=add(dp[i],1ll*(n-1)*(n-1)%mod);
//		cout<<dp[i]<<endl;
		dp[i]=add(dp[i],add(suf[i+3],mod-suf[i+n+2]));
//		cout<<dp[i]<<endl;
		suf[i]=add(dp[i],suf[i+1]);
	}
	printf("%d\n",dp[1]);
	return 0;
}


Measured memory_bytes: 15872
#!/usr/bin/env ruby

if __FILE__ == $0 then
    point = [0]*2
    n = gets.chomp.to_i

	n.times do
        t, h = gets.split
        if t == h then
			point.map!{ |x| x+1 }
		else
            point[t<h ? 1 : 0] += 3
		end
	end
	puts '%d %d' % point
end


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

using namespace std;
char s[29];
int vis[29];
int a[29];
char com[29]={"zyxwvutsrqponmlkjihgfedcba"};
void nextPermutation(vector<int> &num)
{
    int i, j, n = num.size();
    for (i = n - 2; i >= 0; --i)
    {
        if (num[i + 1] > num[i])
        {
            for (j = n - 1; j >= i; --j)
            {
                if (num[j] > num[i]) break;
            }
            swap(num[i], num[j]);
            reverse(num.begin() + i + 1, num.end());
            cout<<endl;
            return;
        }
    }
    reverse(num.begin(), num.end());
}

int main()
{
    cin>>s;
    if(strcmp(s,com)==0){
        printf("-1\n");
    return 0;
   }
    int n=strlen(s),len=n;
    memset(vis,0,sizeof(vis));
    for(int i=0; i<n; i++)
    {
        a[i]=s[i]-'a'+1;
        vis[a[i]]++;
    }

    if(n<26)
    {
        printf("%s",s);
        for(int i=1; i<=26; i++)
            if(vis[i]==0){
                printf("%c\n",'a'+i-1);
                break;
            }
    }

    else
    {
        int i=0;
        vector<int> num;
        while(n--)
        {
            num.push_back(a[i]);
            i++;
        }
        nextPermutation(num);
        for(int i = 0; i < num.size(); i++)
        {
            if(num[i]==a[i])
                printf("%c",num[i]+'a'-1);
            else
            {
                printf("%c\n",num[i]+'a'-1);
                break;
            }

        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main() {
    string x;
    cin >> x;
    int n=x.size();
    int c=0;
    int ans=0;
    for (int i=0;i<n;i++) {
        if (x[i]=='S') c++;
        else {
            if (c>0) c--;
            else ans++;
        }
    }
    ans+=c;
    cout << ans << endl;
}

Measured memory_bytes: 640
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

template<class T>
using vec = std::vector<T>;

template<class T>
using vec2d = std::vector<std::vector<T>>;


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


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto k = next<int>(in);
  vec2d<int> g(n);
  FOR(i, n-1) {
    auto x = next<int>(in) - 1;
    auto y = next<int>(in) - 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vec<int> u(n, 0);
  int marked = 0;

  function<void(int, int, int)> dfs = [&] (int v, int p, int k) {
    u[v] = true;
    ++marked;
    if (k == 0) {
      return;
    }
    for (auto to : g[v]) {
      if (to != p) {
        dfs(to, v, k-1);
      }
    }
  };

  int res = n - k;
  if (k % 2 == 1) {
    FOR(i, n) {
      for (auto to : g[i]) {
        u = vec<int>(n, 0);
        marked = 0;
        dfs(to, i, k / 2);
        dfs(i, to, k / 2);
        res = min(res, n - marked);
      }
    }
  } else {
    FOR(i, n) {
      u = vec<int>(n, 0);
      marked = 0;
      dfs(i, -1, k / 2);
      res = min(res, n - marked);
    }
  }
  out << res << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n, m;
vector<char> g[10];

int solve(string s, char c) {
  s += c;

  if(s.length() == n) return 1;
  int p = (int)(s[s.length() - 1] - 48);
  int num = 0;
  rep(i, 0, g[p].size()) {
    bool f = 0;
    rep(j, 0, s.length()) if((char)(g[p][i] + 48) == s[j]) f = 1;
    if(f) continue;
    num += solve(s, (char)(g[p][i] + 48));
  }
  return num;
}

signed main() {
  cin >> n >> m;

  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    g[a].pb(b);
    g[b].pb(a);
  }

  cout << solve("", '1') << endl;
}


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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;

    if (s.size() + 1 == t.size()) {
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3604
#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 ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;


void solve(){
    ll A;
    cin >> A;
    string b;
    cin >> b;
    ll B = 0;
    ll cur = 100;
    REP(i,b.size()){
        if(b[i] == '.') continue;
        B += cur * (b[i] - '0');
        cur /= 10;
    }
    ll ans = A * B / 100;
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3640
from sys import stdin
input = stdin.readline


def check(min_, max_, x):
  if x < min_:
    return 0
  else:
    return int((min(max_, x) - min_)/10) + 1


def main():
  N = int(input())

  if len(str(N)) == 1:
    print(N)
    return
  sum_ = 0
  for l in range(1, 10):
    for r in range(l, 10):
      temp = sum_
      min_ = int(str(l) + '0'*(len(str(N))-2) + str(r))
      max_ = int(str(l) + '9'*(len(str(N))-2) + str(r))
      A = check(min_, max_, N)
      # max_ = int(str(l) + '9'*(len(str(N))-3) + str(r))
      for gap in range(len(str(N))-2):
        A += (10**gap)

      min_ = int(str(r) + '0'*(len(str(N))-2) + str(l))
      max_ = int(str(r) + '9'*(len(str(N))-2) + str(l))
      B = check(min_, max_, N)
      for gap in range(len(str(N))-2):
        B += (10**gap)

      if l == r:
        A += 1
        B += 1
        sum_ += A*B
      else:
        sum_ += 2*A*B
      # print(l, r, sum_ - temp)

  print(sum_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 62432