akhauriyash/Code-Regression huggingface dataset:
from collections import deque

ans = []
while True:
    w, h = map(int, input().split())

    if w == 0 and h == 0:
        break
    
    col = []
    row = []
    for i in range(2*h-1):
        if i % 2 == 0:
            col.append(list(map(int, input().split())))
        else:
            row.append(list(map(int, input().split())))
    
    dwdh = [(1, 0), (-1, 0), (0, 1), (0, -1)]

    d = [[0] * w for _ in range(h)]

    que = deque([(0, 0)])
    d[0][0] = 1
    while que:
        qw, qh = que.popleft()

        for dw, dh in dwdh:
            nw = qw + dw
            nh = qh + dh
            if not(0 <= nh < h) or not(0 <= nw < w) or d[nh][nw]:
                continue
            if (dh == -1 and row[nh][nw] == 1) or (dh == 1 and row[nh-1][nw]==1):
                continue
            if (dw == -1 and col[nh][nw] == 1) or (dw == 1 and col[nh][nw-1] == 1):
                continue

            que.append((nw, nh))
            d[nh][nw] = d[qh][qw] + 1

    ans.append(d[h-1][w-1])

for a in ans:
    print(a)


Measured memory_bytes: 6044
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string,int> dic;

    for(int i = 0; i < n; ++i)
    {
        string t;
        cin >> t;
        if(dic.count(t) == 0)
        {
            dic[t] = 1;
        }
        else
        {
            dic[t] += 1;
        }
    }

    int current = 0;
    vector<string> ans;
    for(pair<string,int> d : dic)
    {
        if(d.second > current)
        {
            current = d.second;
            ans.clear();
            ans.push_back(d.first);
        }
        else if(d.second == current)
        {
            ans.push_back(d.first);
        }
    }

    for(string str : ans)
    {
        cout << str << endl;
    }
}

Measured memory_bytes: 26868
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;


int main() {
	int N; cin >> N;
	vector<pair<ll, ll>> v(N);

	for (int i = 0; i < N; i++) {
		ll x, l; cin >> x >> l;
		v[i].first = x + l;
		v[i].second = x - l;
	}
	sort(v.begin(), v.end());

	ll m = -1000000000000000LL;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (v[i].second >= m) {
			m = v[i].first;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
a = list(map(int, input().split()))
x = a[0]
k = a[1]
d = a[2]
x = abs(x)

if abs(x) - k*d >= -d:
    print(abs(abs(x) - k*d))
else:
    t = x // d
    x = x - d*t
    k = k - t
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {

    int n;
    string s;

    cin >> n >> s;

    if(n % 2 == 0) {
        string t1, t2;
        t1 = s.substr(0, n/2);
        t2 = s.substr(n/2, n/2);
        cout << (t1 == t2 ? "Yes" : "No"); 
    }else
    {
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MAX_DIGIT = 60;
long long dp[100][2];

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

    int d;
    cin >> d;
    if (d == 25) {
        cout << "Christmas\n";
    } else if (d == 24) {
        cout << "Christmas Eve\n";
    } else if (d == 23) {
        cout << "Christmas Eve Eve\n";
    } else if (d == 22) {
        cout << "Christmas Eve Eve Eve\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    // input
    static int n;
    static int k;

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){
        int ans;

        ans = n-k+1;

        System.out.println(ans);
    }

    public static void main(String args[]) {

        input();

        solve();
    }
}


Measured memory_bytes: 23764
#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;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll ans=0;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	for(int i=1;i<n/2;i++){
		ll sum=0;
		int l=0,r=n-1;
		while(l<n&&i<r&&l+i<n&&l!=r){
			sum+=v[l]+v[r];
			chmax(ans,sum);
			//puta(l,r,sum);
			if(l+i==r)l=n;
			l+=i,r-=i;
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct node
{
    int x,id;
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
}a[N];
int n,ans[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i].x),a[i].id=i;
    sort(a+1,a+1+n);
    int k=n/2;
    for(int i=1;i<=n;i++)
        if(k<i) ans[a[i].id]=a[k].x;
    else ans[a[i].id]=a[k+1].x;
    for(int i=1;i<=n;i++)
        printf("%d\n",ans[i]);
}


Measured memory_bytes: 4480
using System;
using System.Linq;
namespace ConsoleTest {
  class Program {
    static void Main(string[] args) {
      int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      if (a[0] < 9 && a[1] < 9) {
        Console.WriteLine("Yay!");
      } else {
        Console.WriteLine(":(");
      }
    }
  }
}

Measured memory_bytes: 13268
#from operator import itemgetter
n = int(input())
d = []

for i in range(n):
    s,p = input().split()
    p = int(p)*-1
    d.append([s,p,i+1])

#整数は*(-1)をしてそーとした時に昇順にできればいい>通し番号が正しければ良い
d.sort()#list.sort(key=itemgetter(要素番号))＜デフォルト

for i in range(n):
    print(d[i][2])

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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if ( H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
import scala.io.StdIn._

object Main extends App {


  val Array(n,m) = readLine().split(" ").map(_.toInt)
  val resultArr = Array.fill(m)(readLine().split(" "))
    .map(list => (list(0).toInt-1, list(1)))

  def solve() = {
    var cntAC = 0
    var cntWA = 0
    val historyArr = Array.fill(n, 2)(0)
    resultArr.foreach { case (p, s) =>
      if(s == "WA") {
        historyArr(p)(1) += 1
      } else if(s == "AC" && historyArr(p)(0) == 0) {
        cntAC += 1
        cntWA += historyArr(p)(1)
        historyArr(p)(0) = 1
      }
    }
    s"$cntAC $cntWA"
  }

  println(solve())

}



Measured memory_bytes: 74336
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    tuple<string,intl,intl> t[n];
    rep(i,n){
        string s;
        intl p;
        cin >> s >> p;
        t[i] = make_tuple(s,-p,i + 1);
    }
    sort(t,t + n);
    rep(i,n){
        cout << get<2>(t[i]) << endl;
    }
    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1'000'000'000;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> to[n];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  // BFS
  queue<int> q;
  vector<int> pre(n); // 1つ前の部屋番号(0 indexed)
  vector<int> dist(n, INF); // 距離(未使用)
  dist.at(0) = 0;
  q.push(0);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i : to[t]) {
      if (dist.at(i) != INF) {
        continue;
      }
      q.push(i);
      pre.at(i) = t;
      dist.at(i) = dist.at(t)++;
    }
  }
  // 出力
  cout << "Yes" << endl;
  rep(i, n) {
    if (i == 0) {
      continue;
    }
    int res = pre.at(i);
    res++;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 10524
#include <stdio.h>
int main(void){
    // Your code here!
    int S;
    int h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
    
    
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;

signed main()
 {
   
    int a,b,c;
      cin>>a>>b>>c;
      cout<<c<<" "<<a<<" "<<b;
      
     return 0;
}

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

int main( void ) {
    int n, m;
    while(cin >> n >> m && n + m){
        char ch = '#';
        for( int i = 0; i < n; ++i ) {
            char x = ch;
            ch = ch == '#' ? '.' : '#';
            for( int j = 0; j < m; ++j ) {
                cout << x;
                x = x == '#' ? '.' : '#';
            }
            cout << '\n';
        }
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <math.h>

int main()
{
    double a,b,c,S,L;
    scanf("%lf %lf %lf",&a,&b,&c);
    S = a*b*sin(c*M_PI/180)/2;
    L = sqrt(a*a+b*b-2*a*b*cos(M_PI*c/180));
    printf("%.8lf %.8lf %.8lf\n",S,a+b+L,2*S/a);
}



Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
static const int MAX = 100000;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> vvb(MAX);
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        a--;
        vvb[a].push_back(b);
    }

    priority_queue<int> Q;
    int out = 0;
    for (int i = 0; i < m; i++) {
        auto vb = vvb[i];
        for (int b : vb) Q.push(b);
        if (Q.empty()) continue;
        out += Q.top();
        Q.pop();
    }

    cout << out << endl;
}


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

int main() {
   ll n,c=0;
  cin>>n;
  vector<pair<int,int > >v;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    v.push_back(make_pair(x,i+1));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)
  {
    cout<<v[i].second<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    string s;
    int K;
    cin >> s >> K;

    vector<string> strings;

    rep(i,s.length()) {
        for (int j = 1; j <= K; j++) {
            strings.push_back(s.substr(i, j));
        } 
    }

    sort(strings.begin(), strings.end());

    int i = 0;
    int n = 1;
    while (i < strings.size()) {
        if (n == K) {
            cout << strings[i] << endl;
            return 0;
        }
        i++;
        if (strings[i] != strings[i - 1]) n++;
    }
    
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,r;
  cin >> h >> r;
  if (h >= 0) {
    cout << 1 << endl;
  } else if (h == r*-1) {
    cout << 0 << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3112
#include <stdio.h>
int main(){
  char s[3];
  scanf("%s",s);
  int i,counta=0,countb=0,countc=0;
  for(i=0;i<3;i++){
    if(s[i]=='a')
     ++counta;
    if(s[i]=='b')
     ++countb;
    if(s[i]=='c')
     ++countc;
   }
  if(counta==1&&countb==1&&countc==1)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 128
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

final = []
for i in range(1, n+1):
    if i <= k:
        final.append("Yes")
        continue
    j = i - k
    if(a[i-1]/a[j-1] > 1):
        final.append("Yes")
    else:
        final.append("No")
    
# print(final)
for i in range(k, n):
    print(final[i])

Measured memory_bytes: 102488
q = int(input())
for i in range(q):
  a, b = list(map(int, input().split()))
  if a==b:
    ans = 2*a-2
  elif abs(a-b)==1:
    ans = 2*min(a, b)-2
  else:
    c = (a*b)**0.5
    if c%1==0:
      c = int(c)-1
    else:
      c = int(c)
    if c*(c+1)>=a*b:
      ans = 2*c-2
    else:
      ans = 2*c-1
  print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int w,h;
int map[30][30];
int W_LR[30][30],W_UD[30][30];
int  judge_UP(int y,int x);
int  judge_DOWN(int y,int x);
int  judge_LEFT(int y,int x);
int  judge_RIGHT(int y,int x);
void func(int y, int x,int p);

int main (void)
{
  int x,y;

  while(1){
    //ú»
    for(y=0;y<30;y++){
      for(x=0;x<30;x++){
	map[y][x]=0;
      }   
    }
    scanf("%d %d",&w,&h);
    
    if(w * h == 0)    
      break;
    
    for(y=0;y<h-1;y++){
      for(x=0;x<w-1;x++){
	scanf(" %d",&W_LR[y][x]);
      }
      for(x=0;x<w;x++){
	scanf(" %d",&W_UD[y][x]);
      }
    }
    for(x=0;x<w-1;x++){
      scanf(" %d",&W_LR[h-1][x]);
    }
    //Èã}bvÇÝÝ

    map[0][0]= 1;
    func(0,0,1);

    printf("%d\n",map[h-1][w-1]);
  }
  return 0;
}

int  judge_UP(int y,int x){
  if(y-1<0)
    return 0;
  else if(W_UD[y-1][x] ==1)
    return 0;
  else 
    return 1;
}
  
int  judge_DOWN(int y,int x){
  if(y+1>=h)
    return 0;
  else if(W_UD[y][x] ==1)
    return 0;
  else 
    return 1;
}
int  judge_LEFT(int y,int x){
  if(x-1<0)
    return 0;
  else if(W_LR[y][x-1] ==1)
    return 0;
  else 
    return 1;
}
int  judge_RIGHT(int y,int x){
  if(x+1>=w)
    return 0;
  else if(W_LR[y][x] ==1)
    return 0;
  else 
    return 1;
}

void func(int y, int x,int p){
  //UP
  if(judge_UP(y,x)){
    if(map[y-1][x] ==0){
      map[y-1][x] = p+1;
      func(y-1,x,p+1);
    }
    else{
      if(map[y-1][x] > p+1){
	map[y-1][x] = p+1;
	func(y-1,x,p+1);
      }
    }
  }
  //DOWN
  if(judge_DOWN(y,x)){
    if(map[y+1][x] ==0){
      map[y+1][x] = p+1;
      func(y+1,x,p+1);
    }
    else{
      if(map[y+1][x] > p+1){
	map[y+1][x] = p+1;
	func(y+1,x,p+1);
      }
    }
  }
  //LEFT
  if(judge_LEFT(y,x)){
    if(map[y][x-1] ==0){
      map[y][x-1] = p+1;
      func(y,x-1,p+1);
    }
    else{
      if(map[y][x-1] > p+1){
	map[y][x-1] = p+1;
	func(y,x-1,p+1);
      }
    }
  }
  //RIGHT
  if(judge_RIGHT(y,x)){
    if(map[y][x+1] ==0){
      map[y][x+1] = p+1;
      func(y,x+1,p+1);
    }
    else{
      if(map[y][x+1] > p+1){
	map[y][x+1] = p+1;
	func(y,x+1,p+1);
      }
    }
  }

}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};

int main() {
    int n, m;
    cin >> n >> m;
    if (n < m) swap(n, m);

    vector<mint> fact(n + 1, 0);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;

    if (n == m) {
        cout << fact[m] * fact[n] * 2 << endl;
        return 0;
    }

    if (n - 1 == m) {
        cout << fact[m] * fact[n] << endl;
        return 0;
    }
    cout << 0 << endl;


}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,kaisu=0;
    cin >> A >> B;

    for(int i=A;i<=B;i++){
        if(i/10000==i%10 && (i/1000)%10==(i/10)%10){
            kaisu++;
        }
    }

    cout << kaisu << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  char s1[12], s2[12];
  scanf("%s%s", s1, s2);
  for(int i=0; i<strlen(s1); i++){
    if(s1[i] != s2[i]){
      printf("No\n");
      return 0;
    }}
  printf("Yes\n");




  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define maxx 1000000007
#define int1 long long int
using namespace std;
int main()
{
    int1 n,k;
    cin>>n>>k;
    int1 a[n];
    for(int1 i=0;i<n;i++)
        cin>>a[i];

    int1 dp[n+1][k+1];
    for(int1 i=0;i<=n;i++)
        dp[i][0]=1;
    for(int1 j=0;j<=k;j++)
       {
           dp[0][j]=1;
       }
       for(int1 j=1;j<=k;j++)
       {
           if(j<=a[0])
            dp[1][j]=1;
           else dp[1][j]=0;
       }



      for(int1 i=2;i<=n;i++)
      {
          int1 st=0;
          int1 csum=dp[i-1][0];
          for(int1 j=1;j<=k;j++)
          {


             /* while(k<=j&&k<=a[i-1])
              {
                  dp[i][j]+=dp[i-1][j-k];
                  k++;
              }*/

              if(a[i-1]>=j)
              {
                  csum+=dp[i-1][j];
                  csum%=maxx;
                  dp[i][j]=csum;
              }
              else
              {
                  csum+=dp[i-1][j];
                  csum-=dp[i-1][st];
                  st++;
                  if(csum<0)
                    csum+=maxx;
                  csum%=maxx;
                  dp[i][j]=csum;
              }
          }
      }
      /*for(int i=0;i<=n;i++)
      {
          cout<<endl;
          for(int j=0;j<=k;j++)
            cout<<dp[i][j]<<" ";
      }*/

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





}


Measured memory_bytes: 79104
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

count = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    count[p - 1] += x

visited = [False] * N
def dfs(v):
    visited[v] = True
    for u in adj[v]:
        if visited[u]:
            continue
        count[u] += count[v]
        dfs(u)

dfs(0)
print(*count)

Measured memory_bytes: 224000
#include <bits/stdc++.h>
#define nmax 500005

using namespace std;

int a[nmax], la[(1<<20)+1], pre[nmax]={};
vector <int> h[(1<<20)+1];

const int mod = 1e9+7;

int powmod(int b, int p){
	int ans=1;
	while(p){
		if(p&1){
			ans=(1ll*ans*b)%mod;
		}
		p>>=1;
		b=(1ll*b*b)%mod;
	}
	return ans;
}

int main(){
	memset(la,-1,sizeof(la));
	int n,z=0; cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(i)
			a[i]^=a[i-1];
		pre[i]=!a[i]+(i?pre[i-1]:0);
		z+=(!a[i]);
		if(la[a[i]]!=-1){
			h[a[i]].push_back(pre[i]-pre[la[a[i]]]);
		}
		la[a[i]]=i;
	}
	int ans=0;
	if(!a[n-1]){
		for(int i=1;i<=(1<<20);i++){
			if(la[i]==-1){
				continue;
			}
			int dp[2]={};
			dp[0]=1, dp[1]=1;
			for(int j=h[i].size()-1;j>=0;j--){
				dp[0]=(dp[0]+1ll*h[i][j]*dp[1])%mod;
				dp[1]=(dp[1]+dp[0])%mod;
			}
			ans=(ans+dp[1])%mod;
		}
		cout << (ans+powmod(2,z-1))%mod << endl;
	}
	else{
		int p=a[n-1];
		int dp[2]={0,1};
		for(int j=h[p].size()-1;j>=0;j--){
			dp[0]=(dp[0]+1ll*h[p][j]*dp[1])%mod;
			dp[1]=(dp[1]+dp[0])%mod;
		}
		cout << dp[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 35708
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    elif op == "?":
        break
    


Measured memory_bytes: 5596
#include <iostream>
#include <map>

signed main() {
  int n;
  std::cin >> n;

  int ans = 0;
  std::map<std::string, int> m;
  for(int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    if(!m[s])
      ans++;
    m[s]++;
  }

  std::cout << ans << std::endl;

  return 0;
}



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

struct node {
  struct node *right;
  struct node *left;
  struct node *parent;
  int val;
};

typedef struct node Node;

Node *root;

void insert(Node *cur, int curVal) {
  if (cur->val == -1) {
    cur->val = curVal;
  }
  else if (curVal < cur->val) {
    if(cur->left == NULL) {
      Node *new = malloc(sizeof(Node));
      new->val = -1;
      new->parent = cur;
      new->left = NULL;
      new->right = NULL;
      //      printf("allocated a node\n");
      cur->left = new;
    }
    insert(cur->left, curVal);
  } else {
    if(cur->right == NULL) {
      Node *new = malloc(sizeof(Node));
      new->val = -1;
      new->parent = cur;
      new->left = NULL;
      new->right = NULL;
      //printf("allocated a node\n");
      cur->right = new;
    }
    insert(cur->right, curVal);
  }
}

void inorder(Node *cur){
  if (cur == NULL)
    return;

  inorder(cur->left);
  printf(" %d", cur->val);
  inorder(cur->right);
}

void preorder(Node *cur){
  if (cur == NULL)
    return;

  printf(" %d", cur->val);
  preorder(cur->left);
  preorder(cur->right);
}

Node *find(Node *cur, int search) {
  //  printf("searching for %d\n", search);

  if (cur->val == search) {
    //    printf("yes\n");
    return cur;
  }

  if (cur == NULL) {
    printf("no\n");
    return NULL;
  }

  if (cur->val < search) {
    if (cur->right == NULL) {
      printf("no\n");
      return NULL;
    }
    find(cur->right, search);
  } else {
    if (cur->left == NULL) {
      printf("no\n");
      return NULL;
    }
    find(cur->left, search);
  }
}

Node *treeMinimum(Node *cur) {
  while (cur->left != NULL)
    cur = cur->left;

  return cur;
}

void swap(Node *node1, Node *node2){
  if (node1->parent == NULL)
    root = node2;

  else if (node1 == node1->parent->left)
    node1->parent->left = node2;

  else
    node1->parent->right = node2;

  if(node2 != NULL)
    node2->parent = node1->parent;
}

void delete(Node *cur) {
  Node *y;
  if (cur->left == NULL)
    swap(cur, cur->right);

  else if (cur->right == NULL)
    swap(cur, cur->left);

  else {
    y = treeMinimum(cur->right);

    if (y->parent != cur) {
      swap(y, y->right);
      y->right = cur->right;
      y->right->parent = y;
    }

    swap(cur, y);
    y->left = cur->left;
    y->left->parent = y;
  }
}

int main() {
  int commands, i, num;
  char com[20];

  root = malloc(sizeof(Node));
  root->val = -1;
  root->parent = NULL;
  root->left = NULL;
  root->right = NULL;

  scanf("%d", &commands);

  for (i = 0; i < commands; i++) {
    scanf("%s", &com);
    if (!strcmp(com, "insert")) {
      scanf("%d", &num);
      insert(root, num);
      //printf("inserted!\n");
    } else if (!strcmp(com, "print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (!strcmp(com, "find")) {
      scanf("%d", &num);
      if (find(root, num))
        printf("yes\n");
    } else if (!strcmp(com, "delete")) {
      scanf("%d", &num);
      delete(find(root, num));
    }
  }
}




Measured memory_bytes: 20456
N, K = map(int, input().split())
As = list(map(int, input().split()))

ans = 10**18
for i in range(1<<N):
    cnt = 0
    cost = 0
    mini = 0
    for j in range(N):
        J = As[j]
        if (i>>j)&1:
            cnt += 1
            if mini>=J:
                cost += mini+1-J
                mini += 1
        mini = max(mini, J)
        if cnt>=K:
            ans = min(ans, cost)
print(ans)

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

using namespace std;
int a,b,c; 
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>a>>b;
	c=a+b;
	if(c%2==1) cout<<c/2+1;
	else cout<<c/2;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	double a;
	double f[10];
	while(scanf("%lf",&a)!=EOF){
		f[0]=a;
		int i;
		for(i=0;i<9;i++){
			if(i%2==0){
				f[i+1]=f[i]*2;
			}else{
				f[i+1]=f[i]/3;	
			}
		}
		double sum=0;
		for(i=0;i<10;i++){
			sum += f[i];
		}
		printf("%lf\n",sum);
	}
	return 0;
	}

Measured memory_bytes: 648
use std::vec::Vec;
use std::cmp::*;
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut a: Vec<u64> = read_vec();
  let mut b: Vec<u64> = read_vec();
  let mut c: Vec<u64> = read_vec();
  a.sort();
  c.sort();
  let mut count = 0;
  for x in b {
    let ca = binary_search(&a, |a, i| a[i] >= x);
    let cc = n - binary_search(&c, |c, i| c[i] > x);
    count += ca * cc;
  }
  println!("{}", count);
}

// 条件f(&v, m)を満たす集合の下限を出力する
fn binary_search<F>(v: &Vec<u64>, f: F) -> usize
  where
    F: Fn(&Vec<u64>, usize) -> bool,
{
  let mut lb = 0;
  let mut ub = v.len();

  while ub > lb {
    let m = (ub + lb) / 2;
    if f(&v, m) {
      ub = m;
    } else {
      lb = m + 1;  // 要素v[m]がf(&v, m)を満たさないのでlb = m+1と更新
    }
  }
  lb
}


Measured memory_bytes: 13296
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

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

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

	vector<int>T;
	vector<int>p;
class UnionFind{
public:
	UnionFind(int n){
		T.resize(n);
		p.resize(n);
		for(int i=0;i<n;i++){
			p[i]=i;
		}
	}
	
	int getParent(int n){
		if(p[n]==n)return n;
		return getParent(p[n]);
	}
	bool isSame(int n,int m){
		return getParent(n)==getParent(m);
	}
	void unite(int n,int m){
		int rx=getParent(n);
		int ry=getParent(m);
		p[rx]=ry;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N,W;
	cin>>N>>W;
	vector<ll>w(N);
	vector<ll>v(N);
	for(int i=0;i<N;i++)cin>>w[i]>>v[i];
	
	vector<vector<ll>>dp(N+1,vector<ll>(100005,INF));
	
	//Minimum value of value j with elements up to i
	dp[0][0]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<100005;j++){
			if(dp[i][j]==INF)continue;
			//use i
			dp[i+1][j+v[i]]=
			min(dp[i][j]+w[i],dp[i+1][j+v[i]]);
			
			dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
		}
	}
	ll ans=0;
	for(ll j=0;j<100005;j++){
		if(dp[N][j]==INF)continue;
		//cout<<j<<" "<<dp[N][j]<<endl;
		if(dp[N][j]<=W)ans=max(ans,j);
	}
	cout<<ans<<endl;
}


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

int main() {
    int N; cin >> N;
    
    for (int i=0; i<N; i++) {
        int K, P; cin >> K >> P;
        
        if (K%P==0) {
            cout << P << endl;
        }
        else {
            cout << K%P << endl;
        }
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s;
    cin>>s;
    cout<<s.substr(0,4)<<" "<<s.substr(4)<<endl;
    return 0;
}

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

int main(){
    int n, m;
    long int x[1001] = {}, y[1001] = {}, z[1001] = {}, score[8][1001] = {};

    cin >> n >> m;
    
    // 各ケーキのスコア
    // 足し方を変えて正負いずれの最大化を行うべきかを調べる
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> z[i];
        score[0][i] +=  x[i] + y[i] + z[i];
        score[1][i] +=  x[i] + y[i] - z[i];
        score[2][i] +=  x[i] - y[i] + z[i];
        score[3][i] +=  x[i] - y[i] - z[i];
        score[4][i] += -x[i] + y[i] + z[i];
        score[5][i] += -x[i] + y[i] - z[i];
        score[6][i] += -x[i] - y[i] + z[i];
        score[7][i] += -x[i] - y[i] - z[i];
    }
    
    long int sum[9] = {};

    for(int i=0; i<8; i++){
        sort(score[i], score[i] + n);
        reverse(score[i], score[i] + n);
    }

    // 8通りの総合スコアの求め方の最大値を求める
    for(int i=0; i<m; i++){
        for(int k=0; k<8; k++){
            sum[k] += score[k][i];   
        }
    }

    long int maximum = -10000000000000;
    int maxindex = -1;
    for(int i=0; i<8; i++){
        maximum = max(sum[i], maximum);
        if(maximum == sum[i]){
            maxindex = i;
        }
    }

    sort(score[maxindex], score[maxindex] + n);
    reverse(score[maxindex], score[maxindex] + n);

    long int result = 0;
    for(int i=0; i<m; i++){
        result += score[maxindex][i];
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 384
# coding: utf-8
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 9)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
# 奇数の時と偶数の時、奇数の場合は真ん中を選ぶかどうか
INF = 10 ** 17

@lru_cache(None)
def F(index, n):
    if index >= N:
        return -INF
    if N - index + 2 < 2 * n:
        return -INF
    if n == 0:
        return 0
    elif n == 1:
        return max(A[index:])
    ret = max(A[index] + F(index+2, n-1), F(index+1, n))
    return ret

answer = F(0, N//2)
print(answer)


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

int SumOfDigits(int n){
	int sum=0;
	while(true){
		if (n==0) break;
		sum += n%10;
		n/=10;
	}
	return sum;
}

int main(){
	int N;
	cin>>N;
	int ans=N;
	for(int a=1;a<N;++a){
		int b=N-a;
		if(ans>SumOfDigits(a)+SumOfDigits(b)) ans=SumOfDigits(a)+SumOfDigits(b);
	}
	cout<<ans<<endl;
}


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

int main(){
	double a,b,c; cin >> a >> b >> c;
	double rad = M_PI/180.0*c;
	double h = b*sin(rad);
	double S = 0.5*a*h;
	double L = a + b + sqrt(a*a+b*b-2*a*b*cos(rad));

	cout << fixed << setprecision(8) << S << endl;
	cout << fixed << setprecision(8) << L << endl;
	cout << fixed << setprecision(8) << h << endl;

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cctype>

int main() {
    constexpr int Size = 'z' - 'a' + 1;
    int nums[Size]{};
    std::string s{};
    while(std::cin >> s) {
        for(auto c : s) {
            if(!isalpha(c)) continue;
            nums[tolower(c)-'a']++;
        }
    }
    for(auto i=0; i<Size; i++) {
        std::cout << char('a'+i) << " : " << nums[i] << std::endl;
    }
}



Measured memory_bytes: 3192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int s_cmp(const void *a, const void *b)
{
	return strcmp(*(char**)a, *(char**)b);
}

int main()
{
	int N, L;
	scanf("%d%d", &N, &L);
	char **s;
	int i = 0;
	s = malloc(sizeof(char*) * N);
	while (i < N)
	{
		s[i] = malloc(sizeof(char) * (L + 1));
		scanf("%s", s[i]);
		i++;
	}
	qsort(s,N, sizeof *s,s_cmp);
	i = 0;
	while (i < N)
		printf("%s",s[i++]);
	return (0);
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    long long n,ans=0,l=0,r=0;
    scanf("%lld",&n);
    long long a[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    long long s=a[0],x=a[0];
    for (l=0; l<n; l++){
        while(r+1<n && (s+a[r+1])==(x^a[r+1])){
            r++;
            s+=a[r];
            x^=a[r];
        }
        ans+=r-l+1;
        if (r==l){
            r++;
            s=a[l+1];
            x=a[l+1];
        } else {
            s=s-a[l];
            x=x^a[l];
        }
    }
    printf("%lld\n",ans);
    return 0;    
}

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#define MAX_N 100001
using namespace std;

bool isPrime(int n) {
  if (n == 0 || n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 2 == 0) return false;
  for (int i = 5; i <= sqrt(n); i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int nc = n;
  cout << n << ':';
  if (isPrime(n) == true) {
    cout << ' ' << n << endl;
    return 0;
  }
  for (int i = 2; i <= nc; i++) {
    if (isPrime(i) == false) continue;
    if (nc % i) continue;
    while (nc % i == 0) {
      cout << ' ' << i;
      nc /= i;
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()
using namespace std;


const int maxn=1e6+7;
vector<int>vec[maxn];

int s,t;

bool vis[maxn];

ll d[maxn];

void bfs(){
    memset(d,-1,sizeof(d));
    memset(vis,0,sizeof(vis));
    queue<int>q;
    q.push(3*s),d[3*s]=0;
    while(!q.empty()){
        int now=q.front();
        q.pop();
        if(vis[now]) continue;
        vis[now]=1;
        for(int x:vec[now]){
            if(!vis[x]) d[x]=d[now]+1,q.push(x);
        }
    }
    if(d[3*t]>=0) cout<<d[3*t]/3<<endl;
    else cout<<-1<<endl;
}

int main (){
    int n,m;scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        int x,y;scanf("%d %d",&x,&y);
        vec[3*x].push_back(3*y+1);
        vec[3*x+1].push_back(3*y+2);
        vec[3*x+2].push_back(3*y);
    }
    cin>>s>>t;
    bfs();
    return 0;
}


Measured memory_bytes: 41856
import math

data = input().split()  

k = int(data[0])
a = int(data[1])
b = int(data[2])


bi=1


if(a+2>=b):
    bi=k+1
elif((a+2)>(k+1)):
    bi=k+1
else:
    bi+=(b-a)+(a-1)
    k-=(a+1)
    bn = math.floor(k/2)
    bb = k%2
    bi+=(bn*(b-a) + bb)

print(bi)

Measured memory_bytes: 3064
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    LONG N, K;
    cin >> N >> K;

    LVEC A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }

    vector<LONG> locations(N, -1);
    vector<LONG> positions(N, -1);

    locations[0] = 0;
    positions[0] = 0;

    LONG cur = 0;
    LONG loop_start = -1;
    LONG loop_end = -1;

    while(cur < N){
        LONG next = A[locations[cur]] - 1;

        if(positions[next] != -1){
            loop_end = cur;
            loop_start = positions[next];
            break;
        }

        ++cur;
        locations[cur] = next;
        positions[next] = cur;
    }

    if(K <= loop_start){
        cout << locations[K] + 1;
    }
    else{
        LONG rest = (K - loop_start) % (loop_end - loop_start + 1);
        cout << locations[loop_start + rest] + 1;
    }
}


Measured memory_bytes: 8012
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int a; cin >> a;

    cout << a + a*a + a*a*a << endl;

    return 0;
}


Measured memory_bytes: 3596
N = gets.to_i
S = gets.chomp
Q = gets
Qs = readlines.map(&:split)

@h = Hash.new{|h, k| h[k] = []}
@s = "_" + S.dup
S.each_char.with_index(1){|c, i| @h[c] << i}

def update(i, c)
  d = @s[i]
  return if c == d
  @s[i] = c
  @h[d].delete_at(@h[d].bsearch_index{|x| x >= i})
  @h[c].insert((@h[c].bsearch_index{|x| x >= i} || -1), i)
end

def kind(l, r)
  ('a' .. 'z').count{|c| (@h[c].bsearch_index{|x| x >= l} || N + 1) < (@h[c].bsearch_index{|x| x > r} || N + 1)}
end

Qs.each do |a, b, c|
  if a == '1'
    update(b.to_i, c)
  else
    puts kind(b.to_i, c.to_i)
  end
end


Measured memory_bytes: 18464
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,m,n;
    ll t;
    char c;
    cin>>c;
    if(c<='Z')
        cout<<"A";
    else
        cout<<"a";
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
typedef long double ld;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
bool ok;
int nxt[500010],f[500010],d[500010],l,r,o,ans,L,R,O,n,x,y,hed[500010],too[500010],nedge,stk[500010],top;
void ae(int x,int y){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
}
bool check(int o){
	int p=0,q=top+1;
	FOR(i,1,top/2){
		++p,--q;
		if (p==o) ++p;
		if (q==o) --q;
		if (stk[p]+stk[q]>O) return 0;
	}
	return 1;
}
void dfs(int x,int l){
	if (!ok) return;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		dfs(y,x);
	}
	top=0;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		stk[++top]=f[y];
		if (f[y]==-1){ok=0;return;}
	}
	if (x==1){
		sort(stk+1,stk+top+1);
		if (top&1) ok&=check(top);
		else ok&=check(-1);
		return;
	}
	if (d[x]%2==0){
		sort(stk+1,stk+top+1);
		if (!check(top)){f[x]=-1;return;}
		l=1,r=top;
		while (l<r){
			o=l+r>>1;
			if (check(o)) r=o;
			else l=o+1;
		}
		f[x]=(stk[r]+1<=O)?stk[r]+1:(-1);
	}
	else{
		stk[++top]=0;
		sort(stk+1,stk+top+1);
		if (!check(top)){f[x]=-1;return;}
		l=1,r=top;
		while (l<r){
			o=l+r>>1;
			if (check(o)) r=o;
			else l=o+1;
		}
		f[x]=(stk[r]+1<=O)?stk[r]+1:(-1);
	}
}
int main(){
	scanf("%d",&n);
	FOR(i,2,n){
		getint(x),getint(y);
		ae(x,y),ae(y,x);
		++d[x],++d[y];
	}
	FOR(i,1,n) ans+=d[i]&1;
	cout<<ans/2<<' ';
	++d[1];
	L=1,R=n;
	while (L<R){
		O=L+R>>1;
		ok=1;
		dfs(1,0);
		if (ok) R=O;
		else L=O+1;
	}
	cout<<R<<endl;
	return 0;
}


Measured memory_bytes: 12800