akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

ll gcd(ll A, ll B)
{
    if(B==0) return A;
    return gcd(B, A%B);
}

int main()
{
    ll A, B;
    cin >> A >> B;

    ll d = gcd(A, B);
    if(d == 1){cout << 1 << endl; return 0;}

    int M = sqrt(d);
    vector<ll> e;
    for(int i=2; i<=M; i++){
        e.push_back(0);
        while(d%i==0){
            d /= i; e.back()++;
        }
        if(e.back()==0) e.pop_back();
    }
    if(d != 1) e.push_back(1);

    cout << e.size()+1 << endl;
}

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

using namespace std;

int main() {
	vector<string> v;
	string str;
	while (cin >> str) {
		v.push_back(str);
	}
	vector<string>::iterator it = v.begin();
	int ifs = 1, loc;
	while (it != v.end()) {
		if (ifs == 0)
			cout << " ";
		if ((loc = it->find("apple", 0)) != string::npos)
			it->replace(loc, 5, "peach");
		else if ((loc = it->find("peach", 0)) != string::npos)
			it->replace(loc, 5, "apple");
		cout << *it;
		ifs = 0;
		it++;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1196
#include <string.h>

int main(void){
    char InputRing[202];
    char InputF[101];
    char Input[101];
    int a,b,ok=0;
    int i=0,j=0;
    
    scanf("%s",InputF);
    scanf("%s",Input);
    
    strcat(InputRing,InputF);
    strcat(InputRing, InputF);
    a=(int)strlen(Input);
    b=(int)strlen(InputRing);
    
    while(1){
        if(InputRing[i]==Input[0]){
            if(a==1) ok=1;
            for(j=1;j<a;j++){
                if(InputRing[i+j]!=Input[j]) break;
                if(a==j+1) ok=1;
            }
        }
        i++;
        if(b==i) break;
    }
    if(ok==1){
        printf("Yes");
    }else{
        printf("No");
    }
    printf("\n",ok);
    
}


Measured memory_bytes: 2108
import java.util.*;
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String ans="Yes";
		//回分判定1
		for(int i=1;i<=(S.length());i++){
			if(S.charAt(i-1)==S.charAt(S.length()-i)){
			}
			else{
			ans="No";
			}
		}
		//回分判定2
		for(int i=1;i<=(S.length()-1)/2;i++){
			if(S.charAt(i-1)==S.charAt(((S.length()-1)/2)-i)){
			}
			else{
			ans="No";
			}
		}
		//回分判定3
		for(int i=(S.length()+3)/2;i<=(S.length());i++){
			if(S.charAt(i-1)==S.charAt(((S.length()+3)/2)+(S.length())-i-1)){
			}
			else{
			ans="No";
			}
		}
		System.out.println(ans);
        }
    }

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

#define NDEBUG

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m); n++;
	std::string s; cin >> s;

	// solve
	using P = std::pair<int, int>;
	// (val, lifetime)
	
	std::vector<int> dp(n + 1, 1 << 30); dp[0] = 0;
	std::vector<int> from(n + 1, -1);
	std::queue<P> qu({{0, -m}});
	for(int i = 0; i < n; i++) {
		if(s[i] == '1') continue;
		
		while(!qu.empty() and (i - qu.front().second) > m) qu.pop();
		if(qu.empty()) break;

		dp[i + 1] = qu.front().first + 1;
		from[i + 1] = qu.front().second + 1;
		qu.push({dp[i + 1], i});
	}

	#ifndef NDEBUG
	for(auto v: dp) cerr << v << " "; cerr << endl;
	for(auto v: from) cerr << v << " "; cerr << endl;
	#endif
	
	if(dp[n] == 1 << 30) {
		printf("-1\n");
		return 0;
	}

	int now = n;
	std::vector<int> ans;
	while(now > 1) {
		ans.push_back(now - from[now]);

		now = from[now];
	}
	reverse(begin(ans), end(ans));
	
	for(auto v: ans) printf("%d ", v);
	printf("\n");
	return 0;
}



Measured memory_bytes: 1912
#include <stdio.h>
int main() {
    int H, W,j,k;
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        for(j = 0; j < H;j++){
            for(k = 0;k < W; k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



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

int main() {
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (long long i=0; i<N; i++) {
        cin >> A.at(i);
    }

    long long count = 0; //踏み台高さ；
    for (long long i=1; i<N; i++) {
        if (A.at(i) < A.at(i-1)) {
            count += A.at(i-1)-A.at(i);
            A.at(i) = A.at(i-1);
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 4788
// Aizu Vol-3 0327: Alphametic
// 2017.8.25

#include <stdio.h>

int d[10], f[10];
int b[10] = { 0, 1, 10, 1, 100, 10, 1, 100, 10, 1 };
int cnt;

void combi(int i, int n, int s)
{
	int j, t;

	if (i == 10) { if (n == s) cnt++; return; }
	if (d[i] >= 0) {
		t = d[i] * b[i];
		if (i >= 7)	combi(i + 1, n, s + t);
		else        combi(i + 1, n + t, s);
	} else {
		for (j = 1; j <= 9; j++) {
			if (f[j]) continue;
			f[j] = 1;
			t = j * b[i];
			if (i >= 7)	combi(i + 1, n, s + t);
			else        combi(i + 1, n + t, s);
			f[j] = 0;
		}
	}
}

int main()
{
	int i;

	for (i = 1; i <= 9; i++) f[i] = 0;
	for (i = 1; i <= 9; i++) {
		scanf("%d", d + i);
		if (d[i] >= 0) f[d[i]] = 1;
	}
	cnt = 0;
	combi(1, 0, 0);
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int sum = 0;
    for(int i = 1;i <= n;i++){
      sum = sum + 800;
      if(i%15 == 0){
        sum = sum - 200;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23508
#include<stdio.h>

int sensearch(int *,int,int);

int main()
{
  int n,i,key,sum=0,q;

  scanf("%d",&n);

  int a[n];

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      if(sensearch(&a[0],n,key))sum++;
    }
  printf("%d\n",sum);

  return 0;
}

int sensearch(int *a,int n,int key)
{
  int i=0;
  a[n]=key;
  while(a[i]!=key)i++;

  return i != n;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string s;
int dp[100001][2];

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	dp[0][0] = 0, dp[0][1] = -1;
	for(int i = 1; i <= (int)s.length(); i++){
		dp[i][0] = (s[i - 1] == 'g') + dp[i - 1][1];
		dp[i][1] = dp[i - 1][0] - (s[i - 1] == 'p');
	}
	cout << dp[(int)s.length()][0] << "\n";
	return 0;
}

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

int main(){
  int n;
  cin >>n;
  vector<int> c(n-1),s(n-1),f(n-1);
  for(int i=0;i<n-1;i++){
    cin >>c[i] >>s[i] >>f[i];
  }

  vector<int> b(n-1),tt(n);
  for(int j=0;j<n-1;j++){
    for(int i=0;i<n-1;i++) b[i] = 0;
    b[j] = s[j];
    for(int i=j+1;i<n-1;i++){
      b[i] = b[i-1]+c[i-1];
      if(b[i] < s[i]){
        b[i] = s[i];
      }else if(b[i] > s[i]){
        if(b[i]%f[i] != 0){
          b[i] = (b[i]/f[i]+1)*f[i];
        }
      }
    }
    tt[j] = b[n-2]+c[n-2];
  }
  tt[n-1] = 0;

  for(int i=0;i<n-1;i++) cout <<tt[i] <<endl;
  cout <<tt[n-1] <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct Node
{
   string name;
   int time;
};
int main()
{
   int n,q;
   cin>>n>>q;
   queue<Node>qe;
   for(int i=0;i<n;i++)
   {
      Node temp;
      cin>>temp.name;
      cin>>temp.time;
      qe.push(temp);
   }
   int endTime=0;
   while(!qe.empty())
   {
      Node temp=qe.front();
      qe.pop();
      if(temp.time-q<=0)
      {
         endTime+=temp.time;
         cout<<temp.name<<" "<<endTime<<endl;
      }
      else
      {
         endTime+=q;
         temp.time-=q;
         qe.push(temp);
      }
   }
   return 0;
}

Measured memory_bytes: 6392
#include<stdio.h>
main(void)
{
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		
		if(op=='+')
		printf("%d\n",a+b);
		
		else if(op=='-')
		printf("%d\n",a-b);
		
		else if(op=='*')
		printf("%d\n",a*b);
		
		else if(op=='/')
		printf("%d\n",a/b);
		
		else if(op=='?')
		break;
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, d, x;
    cin >> n >> d >> x;
    int ans = x;
    rep(i, n) {
        int a;
        cin >> a;
        ans += (d-1)/a+1;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  char exp[100] = {}, *el;
  double stack[100] = {}, n;
  int i, j;
  while(fgets(exp, sizeof(exp), stdin) != NULL){
    for(i = 0;i < 100;i++) stack[i] = 0;
    i = 0;
    for(el = strtok(exp, " \n");el != NULL;el = strtok(NULL, " \n")){
      if(*el == '+') stack[i - 2] += stack[--i];
      else if(*el == '-' && strlen(el) == 1) stack[i - 2] -= stack[--i];
      else if(*el == '*') stack[i - 2] *= stack[--i];
      else if(*el == '/') stack[i - 2] /= stack[--i];
      else stack[i++] = atof(el);
    }
    printf("%.6f\n", stack[0]); 
  }
  return 0;
}

Measured memory_bytes: 588
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int[] kids = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		Arrays.sort(kids);
		Main main = new Main();

		System.out.println(main.solve(line[0],line[1],kids));
	}

	public int solve(int N,int x,int[] kids) {
		int con =0;
		int ind =0;
		while (true) {
			if (x - kids[ind] < 0) {
				break;
			}else {
				x = x - kids[ind];
				con++;
			}
			ind++;
			if (ind == N) {
				if (x > 0) {
					con--;
				}
				break;
			}
		}
		return con;
	}
}

Measured memory_bytes: 36160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	int ans = 0;
	vi a(n);
	trav(x, a) cin >> x;
	for(int i = 0; i < n;){
		++ans;
		bool incr = 1, decr = 1;
		do {
			++i;
			incr = incr && (a[i] >= a[i-1]);
			decr = decr && (a[i] <= a[i-1]);
		} while(incr || decr);
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		char[] S = sc.next().toCharArray();
		int Q = sc.nextInt();
		
		boolean rev = false;
		ArrayList<Character> head = new ArrayList<>();
		ArrayList<Character> tail = new ArrayList<>();
		
		for(int i=0; i<Q; i++) {
			int T = sc.nextInt();
			if(T==1) {
				rev ^= true;
			} else {
				int F = sc.nextInt();
				Character C = sc.next().toCharArray()[0];
				if(F==1 ^ rev) {
					head.add(C);
				} else {
					tail.add(C);
				}
			}
		}
		Collections.reverse(head);
		for(char c : S) {
			head.add(c);
		}
		for(char c : tail) {
			head.add(c);
		}
		
		if(rev)
			Collections.reverse(head);
		
		for(Character c : head) {
			pw.print(c);
		}
		pw.println();
		
		pw.close();
		sc.close();
	}
}


Measured memory_bytes: 143116
let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split(' ') |> Array.map int |> Array.toList
 
let rec solve c data =
    match List.skipWhile (fun x -> x <> c) data with
    | [] -> n - c + 1
    | xs -> solve (c + 1) xs
 
solve 1 a
|> fun x -> if x = n then -1 else x
|> printfn "%d"

Measured memory_bytes: 38348
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

// 1 1 2 3 8 15 48 105 384

fn main() {
    input! {
        n: usize
    }

    if n & 1 == 1 {
        println!("0");
    } else {
        let mut factor = 10;
        let mut count = 0;

        while n >= factor {
            // 5^xを因数に持つ偶数のxを数え上げる
            // 偶数なので5ではなく10からスタート
            // 2000 = 2^16 * 5^3なら、10,50,250で1ずつ加算
            count += n / factor;
            factor *= 5;
        }

        println!("{}", count);
    }
}


Measured memory_bytes: 4352
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int modulo(int e) {
    ll b = 10, ret = 1;
    while (e) {
        if (e & 1) ret *= b;
        ret %= 13;
        e >>= 1;
        b *= b;
        b %= 13;
    }
    return (int)ret;

}

int main(void) {
    string S;
    cin >> S;
    int N = S.size();

    vector<vector<int>> dp(N+1,vector<int>(13,0));
    if (S[N-1] == '?') {
        for (int j=0;j<10;j++) dp[1][j] = 1;
    } else {
        dp[1][S[N-1]-'0'] = 1;
    }
    for (int i=2;i<=N;i++) {
        int m = modulo(i-1);
        if (S[N-i] == '?') {
            for (int j=0;j<10;j++) for (int k=0;k<13;k++) {
                dp[i][(j*m+k)%13] += dp[i-1][k];
                dp[i][(j*m+k)%13] %= MOD;
            }
        } else {
            int j = S[N-i]-'0';
            for (int k=0;k<13;k++) {
                dp[i][(j*m+k)%13] += dp[i-1][k];
                dp[i][(j*m+k)%13] %= MOD;
            }
        }
    }

    cout << dp[N][5] << endl;

    return 0;
}


Measured memory_bytes: 8960
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

S=intput()
N=10**9
x=(-S)%N
y=(S+x)//N
print(x,y,N,1,0,0)

Measured memory_bytes: 69180
#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>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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 (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    ll N;
    cin >> N;

    string s;

    while (N > 0) {
        int tmp = N % 26;
        if (tmp == 0) tmp = 26;
        N -= tmp;
        N /= 26;


        tmp--;

        char c = tmp + 'a';
        s += c;
    }

    reverse(all(s));
    cout << s << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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


  
    
  void show(vector<vector<char>> vct){
  for(int i=0;i<vct.size();i++){
      for(int l=0;l<vct[0].size();l++){
            cout<<vct[i][l];
      }
      cout <<endl;
  }
  }  
  

 
int main() {
  
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<vector<char>> vct(n,vector<char>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)  {
        cin>>vct[i][j];
    }
  }
 
  
  for(int i=0;i<vct.size();i++){
      for(int j=0;j<vct[i].size();j++){
          if(vct[i][j]!='.'){
              break;
          }
          if(j==vct[i].size()-1){
            vct.erase(vct.begin() + i);
            i--;
          }
      }
  }
  for(int i=0;i<vct[0].size();i++){
      for(int j=0;j<vct.size();j++){
          if(vct[j][i]!='.'){
              break;
          }
          if(j==vct.size()-1){
             for(int k=0;k<vct.size();k++){
               vct[k].erase(vct[k].begin() + i);  
             }
             i--;
          } 
          
      }
  }
   show(vct);            
              
           
            

  }
 

Measured memory_bytes: 3620
#include<stdio.h>

int main(void){
	int a,b,d,r;
	double fa,fb,f;
	scanf("%d %d",&a,&b);
	fa = (double)a;
	fb = (double)b;
	
	d = a / b;
	r = a % b;
	f = fa/fb;
	printf("%d %d %.5f",d,r,f);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

//#include<bits/stdc++.h>

// #include "beginner_138/beginner_138.h"
// Still dunno how to put linker 

using namespace std; 

int binary_find_index(vector<int>vec, int key){
    // returns index of found element.
    // False: return -1
    int low = 0; int high = vec.size()-1;
    int mid;

    while(low <= high){
        // mid = low + ((high - low) >> 1);
        mid = floor((low + high)/2);
        if(vec[mid] == key){
            return mid;
        }
        else if(vec[mid] > key){
            high = mid-1;
        }
        else if(vec[mid] < key){
            low = mid+1;
        }
    }
    return -1;
}

void c_ques_01(){
    // Exception handling of max value.
    int n, ans;
    cin >> n;

    vector<int> A(n);
    vector<int> A_ord;

    // cout << "Insert " << n << " values: \n";
    // for(int x: A){
    //     cin >> x;
    // }
    for(int i = 0; i < A.size(); i++){
        cin >> A[i];
    }
    A_ord.insert(A_ord.begin(), A.begin(), A.end());
    sort(A_ord.begin(), A_ord.end());


    
    /*
        1. Take code out. Take the max.
        2. Return, 
    */
    // Remove that from A_ord
    // A_it = binary_search(A_ord.begin(), A_ord.end(), A[i]);
    // Take last element, which is the max, cout
    // Return it back to the vector.

    // set<int>::iterator it;



    vector<int>::iterator A_it;
    for(int i = 0; i < A.size(); i++){
        // Find index of that element in the ordered vector
        int index = binary_find_index(A_ord, A[i]);
        // cout << "found index of " << A[i] << " in A_ord at: " << index << endl;
        int val = A_ord[index];

        // Take last element, which is the max, cout
        A_ord.erase(A_ord.begin()+index);
        cout << A_ord[A_ord.size()-1] << "\n";

        // Return it back to the vector.
        A_ord.insert(A_ord.begin()+index,val);
    }

}

void c_ques02(){
    int n, ans;
    cin >> n;

    vector<int> A(n);
    set<int> A_ord;

    for(int i = 0 ; i < n; i++){
        cin >> A[i];
        A_ord.insert(A[i]);
    }

    set<int>::iterator it;
    it = A_ord.end(); --it;
    int max1 = *it;
    A_ord.erase(it); // Removes last element
    it = A_ord.end(); --it;
    int max2 = *it;

    for(int i = 0 ; i < n; i ++){
        if(A[i]== max1)ans = max2;
        else ans = max1;
        cout << ans << "\n";
    }

}

void c_ques03(){
    int n, ans;
    cin >> n;

    vector<int> A(n);
    vector<int> A_ord;

    for(int i = 0 ; i < n; i++){
        cin >> A[i];
    }
    A_ord = A;
    sort(A_ord.begin(), A_ord.end());
    int max = A_ord.at(n-1);
    int max2 = A_ord.at(n-2);

    for(int i = 0; i < n; i++){
        if(A.at(i) == max)cout << max2 << "\n";
        else cout << max << "\n";
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    c_ques03();
    
    
    return 0;
}

// Still bad at implementing C++.

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 998244353;


long long func( long long a, long long b, long long p ) {
    if ( b == 0 ) {
        return 1;
    }
    else if ( b%2 == 0 ) {
        long long temp = func( a, b/2, p );
        return (temp * temp)%p;
    }
    else {
        return ( func( a, b-1, p ) * a ) % p;
    }   
}
 
long long M[300001];
long long D[300001];
 
 
long long Comb( int n, int r ) {
    return (((M[n]*D[r])%MOD)*D[n-r])%MOD;
}

int main() {

    
    M[0] = 1;
    for ( long long i = 1; i <= 300000; i++ ) {
        M[i] = (M[i-1]*i)%MOD;
    }
    D[0] = 1;
    for ( long long i = 1; i <= 300000; i++ ) {
        D[i] = (D[i-1]*func( i, MOD-2, MOD ))%MOD;
    }
 

    long long N,A,B;
    long long K;
    cin >> N >> A >> B >> K;

    long long ans = 0;
    for ( long long a = 0; a <= N; a++ ) {
        if ( A*a <= K && (K-A*a)%B == 0 ) {
            long long b = (K-A*a)/B;
            if ( b <= N ) {
                ans += Comb(N,a)*Comb(N,b);
                ans %= MOD;
            }
        }
    }
    
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4992
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

vector<int> z_algorithm(string s) {
	int n = s.size();
	vector<int> Z(n);
	Z[0] = n;
	int i = 1, j = 0;
	while(i < n) {
		while(i+j < n and s[j] == s[i+j]) j++;
		Z[i] = j;
		if(!j) {
			i++;
			continue;
		}
		int k = 1;
		while(k < j and k+Z[k] < j) {
			Z[i+k] = Z[k];
			k++;
		}
		i += k;
		j -= k;
	}
	return Z;
}

//head

int n;
string s;
int ans = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  rep(i, n-1) {
    vi z = z_algorithm(s.substr(i));
    rep(j, n-i-1) {
      chmax(ans, min(z[j+1], j+1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
main=readLn>>=putStrLn.unwords.map show.(\p->[quot((product(fst p))*(snd p))(4*(product(fst p))-(snd p)*(sum(fst p))),(fst p)!!0,(fst p)!!1]).(\m->[([n,w],m)|n<-[1..3500],w<-[1..3500],4*n*w-m*(n+w)>0,(mod(m*n*w)(4*n*w-m*(n+w)))==0]!!0)

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

vector<pi> ar;

ll st[4*N],lz[4*N];

void updaterange(ll be,ll en,ll pos,ll l,ll r,ll v)
{
    if(lz[pos]!=0)
    {
        st[pos]+=(en-be+1)*lz[pos];
        if(be!=en)
        {
            lz[2*pos+1]+=lz[pos];
            lz[2*pos+2]+=lz[pos];
        }
        lz[pos]=0;
    }
    if(be>r||en<l){return;}
    if(be>=l&&en<=r)
    {
        st[pos]+=(en-be+1)*v;
        if(be!=en)
        {
            lz[2*pos+1]+=v;
            lz[2*pos+2]+=v;
        }
        return;
    }
    ll m=(be+en)/2;
    updaterange(be,m,2*pos+1,l,r,v);
    updaterange(m+1,en,2*pos+2,l,r,v);
    st[pos]=st[2*pos+1]+st[2*pos+2];
}

ll query(ll be,ll en,ll pos,ll l,ll r)
{
    if(lz[pos]!=0)
    {
        st[pos]+=(en-be+1)*lz[pos];
        if(be!=en)
        {
            lz[2*pos+1]+=lz[pos];
            lz[2*pos+2]+=lz[pos];
        }
        lz[pos]=0;
    }
    if(be>r||en<l){return(0);}
    if(be>=l&&en<=r)
    {
        return(st[pos]);
    }
    ll m=(be+en)/2;
    ll p1=query(be,m,2*pos+1,l,r);
    ll p2=query(m+1,en,2*pos+2,l,r);
    return(p1+p2);
}

ll ceil(ll a,ll b)
{
    ll ans=a/b;
    if(a%b!=0){++ans;}
    return ans;
}

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

    ll n,d,a;
    cin>>n>>d>>a;
    ar.resize(n);
    for(ll i=0;i<n;++i){
        cin>>ar[i].first>>ar[i].second;
    }
    sort(ar.begin(),ar.end());
    ll ans=0;

    memset(st,0,sizeof(st));
    memset(lz,0,sizeof(lz));

    for(ll i=0;i<n;++i){
        ll attack=query(0,n-1,0,i,i);
        ll health=ar[i].second-attack*a;
        //cout<<"!!"<<i<<" "<<health<<endl;
        if(health<=0){continue;}
        ll x=ar[i].first+d;
        ll num=ceil(health,a);
        //cout<<"!!"<<i<<" "<<num<<endl;
        ans+=num;
        ll lo=i,hi=n-1,mid,idx;
        while(lo<=hi){
            mid=(lo+hi)/2;
            if(ar[mid].first<=x+d){
                idx=mid;
                lo=mid+1;
            }
            else{
                hi=mid-1;
            }
        }
        //cout<<"!!"<<i<<" "<<idx<<endl;
        updaterange(0,n-1,0,i,idx,num);
    }
    cout<<ans;

    return (0);
}


Measured memory_bytes: 34688
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N);
  vl a(N),b(N);
  in2(N , a , b);
  ll ans = 0;
  repr(i , N){
    a[i] = (a[i] + ans) % b[i];
    if(a[i] != 0) ans += b[i] - a[i];
  }
  out(ans);
}

Measured memory_bytes: 1792
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
string s,t;
int a,b;
int main(){
    cin>>a>>b;
    for(int i=0;i<b;i++)s+=a+'0';
    for(int i=0;i<a;i++)t+=b+'0';
    cout<<min(s,t)<<'\n';
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC58 B

o = input()
e = input()

ans = ''
for i in range(len(o)*2):
    if i % 2 == 0:
        ans += o[i//2]
    else:
        if i // 2 < len(e):
            ans += e[i//2]
print(ans)


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == 5 && B == 5) || (B == 5 && C == 5) || (C == 5 && A == 5)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug(x) cout << #x << " = " << x << endl
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define reset(x) memset(x,0,sizeof(x))
#define up(i,l,r) for(int i=l;i<=r;i++)
#define down(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int n,m,k,Ti;
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>m>>k;
    if(k%n==0||k%m==0){
        cout<<"Yes\n";
        return 0;
    }
    up(i,0,n){
        up(j,0,m){
           Ti=i*m+j*(n-i)-j*i;
           if(Ti==k){
                cout<<"Yes\n";
                return 0;
           }
        }
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    long long N;
    cin >> N;
    vector<long long> s(N);
    for(long long i=0; i<N; i++)
        cin >> s[i];

    long long ans = 0;
    for(long long C=1; C<N-1; C++){
        long long cur = 0;
        long long l = 0, r = N-1;
        for(long long k=0; k<=N; k++){
            bool ok = true;
            for(long long i=1; i<=2; i++){
                if((2*k+i)*C==N-1)
                    ok = false;
            }
            if(!ok) break;
            l += C;
            r -= C;
            if(r <= 0) break;
            if(C >= r) break;
            cur += s[l] + s[r];
            ans = max(ans, cur);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
// atcoder/abc148/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);


  string s;
  while (cin >> s) {
    if ((s.back() - '0') % 2) {
      cout << 0 << endl;
      continue;
    }

    lli n = stoll(s);
    lli sum = 0;
    while (n) {
      sum += n / 5 / 2;
      n /= 5;
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;
int A, B, C;


int main()
{

	int ans;

	cin >> A;
	cin >> B;
	cin >> C;

	int lest = A - B;
	
	if (lest >= C) {
		ans = 0;
	}
	else {
		ans = C - lest;
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#define ll long long
using namespace std;

int w[9], l[9], n, t;
int g[9][9];

ll dfs(int u, int v, int f) {
	ll r = 0;
	if (g[u][v] == -1 || f == g[u][v]) {
		if (f) {
			w[u]++; l[v]++;
			if (w[u] <= t && l[v] <= n - t - 1) {
				if (u == n - 2)
					r = 1;
				else if (v == n - 1)
					r = dfs(u + 1, u + 2, 0) + dfs(u + 1, u + 2, 1);
				else
					r = dfs(u, v + 1, 0) + dfs(u, v + 1, 1);
			}
			w[u]--; l[v]--;
		}
		else if (!f) {
			w[v]++; l[u]++;
			if (w[v] <= t && l[u] <= n - t - 1) {
				if (u == n - 2) 
					r = 1;
				else if (v == n - 1)
					r = dfs(u + 1, u + 2, 0) + dfs(u + 1, u + 2, 1);
				else
					r = dfs(u, v + 1, 0) + dfs(u, v + 1, 1);
			}
			w[v]--; l[u]--;
		}
	}
	return r;
}

int main(void) {
#ifdef _DEBUG
	freopen("1.in", "r", stdin);
#else 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
	int m;
	while (cin >> n, n) {
		t = (n - 1) / 2;
		cin >> m; memset(w, 0, sizeof(w)); memset(l, 0, sizeof(l));
		for (int i = 0; i != n - 1; ++i)
			for (int j = i + 1; j != n; ++j)
				g[i][j] = g[j][i] = -1;
		while (m--) {
			int x, y; cin >> x >> y; x--; y--;
			g[x][y] = 1; g[y][x] = 0;
		}

		cout << dfs(0,1,0) + dfs(0,1,1) << endl;
	}
	return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 101010;
const int MOD = 1e9+7;
int N, M;
vector<pair<int,int> > conn[MAXN];
int S, T;
bool vis[MAXN];
long long mindistS[MAXN];
long long mindistT[MAXN];
long long wayfromS[MAXN];
long long wayfromT[MAXN];

void D( int st, long long mindist[], long long way[])
{
    vector<int> rabbit;
    memset(vis, 0, sizeof(vis));
    using pli = pair<long long, int>;
    priority_queue<pli,vector<pli>,greater<pli>> Q;
    Q.emplace(0, st);
    while(!Q.empty())
    {
        long long dist; int a; tie(dist, a) = Q.top(); Q.pop();
        if(vis[a]) continue; vis[a] = true;
        rabbit.push_back(a);
        mindist[a] = dist;
        for(auto x: conn[a])
            Q.emplace(dist+x.second, x.first);
    }
    way[st] = 1;
    for(auto x: rabbit)
    {
        if(x==st) continue;
        for(auto tmp: conn[x])
        {
            int xydist, y; tie(y, xydist) = tmp;
            if(mindist[y] + xydist == mindist[x])
            {
                //printf("%d %d %d\n",st, x, y);
                way[x] += way[y];
                way[x] %= MOD;
            }
        }
    }
}

int main()
{
    scanf("%d%d", &N, &M);
    scanf("%d%d", &S, &T);
    for(int i=0; i<M; ++i)
    {
        int s, e, x;
        scanf("%d%d%d", &s, &e, &x);
        conn[s].emplace_back(e, x);
        conn[e].emplace_back(s, x);
    }
    vector<int> Sorder, Torder;
    D(S, mindistS, wayfromS);
    D(T, mindistT, wayfromT);
    /*
    for(int i=1; i<=N; ++i)
    {
        printf("%3d->%3d: %3lld/%3lld\n", S, i, mindistS[i], wayfromS[i]);
    }
    for(int i=1; i<=N; ++i)
    {
        printf("%3d->%3d: %3lld/%3lld\n", T, i, mindistT[i], wayfromT[i]);
    }
    */
    long long ans = wayfromS[T] * wayfromS[T] % MOD;
    for(int i=1; i<=N; ++i)
    {
        //not used in shortest path
        if(mindistS[T] != mindistS[i] + mindistT[i]) continue;
        
        if(mindistS[T] == mindistS[i] * 2)
        {
            long long numway = wayfromS[i] * wayfromT[i] % MOD;
            ans -= numway*numway%MOD;
            ans %= MOD; ans += MOD; ans %= MOD;
        }
        for(auto x: conn[i])
        {
            if( mindistS[i] + x.second != mindistS[x.first] ||
                mindistT[x.first] + x.second != mindistT[i]) continue;
            if(mindistS[i] * 2 < mindistS[T] && mindistS[T] < mindistS[x.first]*2)
            {
                long long numway = wayfromS[i] * wayfromT[x.first] % MOD;
                ans -= numway*numway%MOD;
                ans %= MOD; ans += MOD; ans %= MOD;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}
















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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int N;
	cin >> N;
	vector<pair<int, int>> p(N);
	REP(i, N){
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		p[i] = make_pair(tmp1, tmp2); 
	}
	sort(p.begin(), p.end(), compare_by_b);
	ll sum = 0;
	bool b = true;
	REP(i, N){
		sum += p[i].first;
		if(sum > p[i].second) {
			b = false;
			break;
		}
	}
	if(b) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 1792
#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++)
typedef long long ll;

int main(){
  int x;
  int i = 1;
  while(1){
    cin >> x;
    if(x==0)break;
    cout << "Case" << ' ' << i << ": " << x << endl;
    i++;
  }
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

using edge=tuple<ll,ll,bool>;

struct union_find {
	vector<int> rnk, par;
	union_find(int n) {
		rnk.resize(n);
		par.resize(n);
		rep(i, rnk.size()) {
			par[i] = i;
			rnk[i] = 0;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rnk[x] < rnk[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rnk[x] == rnk[y])rnk[x]++;
		}
	}
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w,h;
	int usew=0,useh=0;
	ll ans=0;
	ll in;
	cin>>w>>h;
	union_find uw(w+1),uh(h+1);
	vector<edge> v;
	rep(i,w){
		cin>>in;
		v.push_back(edge(in,i,true));
	}
	rep(i,h){
		cin>>in;
		v.push_back(edge(in,i,false));
	}
	sort(all(v));
	rep(i,v.size()){
		ll node,cost;
		bool fl;
		tie(cost,node,fl)=v[i];
		if(!((fl?uw:uh).same(node,node+1))){
			ans+=(cost*(fl?h+1-useh:w+1-usew));
			(fl?usew++:useh++);
			(fl?uw:uh).unite(node,node+1);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 10096