akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='-') cout<<a-b;
	else cout<<a+b;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/













string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;

    int cnt[2] = { 0, 0 };
    fore(c, S) cnt[c - '0']++;

    int ans = min(cnt[0], cnt[1]) * 2;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#include<map>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int r; cin >> r;
  cout << 3 * r * r;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define trav(a, b) for(auto& a: b)
#define all(a) a.begin(), a.end()
#define gottagofast ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> v(n);
    trav(i, v) cin >> i;
    v.emplace_back(x);
    sort(all(v));
    int g = v[1] - v[0];
    for(int i = 2; i <= n; ++i) {
        g = __gcd(g, v[i] - v[i-1]);
    }
    cout << g;
    return 0;
}

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

using namespace std;
using ll = long long;
const vector<int> dx={+0,+1,+0,-1};
const vector<int> dy={-1,+0,+1,+0};


const vector<int> odx={+1,+1,-1,-1};
const vector<int> ody={-1,+1,+1,-1};
int main() {
    int m,n;
    cin>>m>>n;
    vector<vector<char>> d(m,vector<char>(n,'@'));
    for(int i = 0;i < m;++i) {
        for(int j = 0;j < n;++j) {
            cin>>d[i][j];
        }
    }
    vector<vector<char>> ans(m,vector<char>(n,'@'));
    for(int i = 0;i < n;++i) {
        ans[0][i]='p';
    }
    for(int i = 0;i < m;++i) {
        for(int j = 0;j < n;++j) {
            if(d[i][j]=='o') {
                ans[i][j]='p';
                for(int dir = -1;dir < 2;++dir) {
                    int ny=i,nx=j+dir;
                    if(ny<0||ny>=m||nx<0||nx>=n)continue;
                    ans[ny][nx]='p';
                }
            }
            else if(d[i][j]=='x') {
                ans[i][j]='p';
                for(int dir = 0;dir < 4;++dir) {
                    int ny=i+dx[dir],nx=j+dy[dir];
                    if(ny<0||ny>=m||nx<0||nx>=n)continue;
                    ans[ny][nx]='p';
                }
                for(int dir = 0;dir < 4;++dir) {
                    int ny=i+odx[dir],nx=j+ody[dir];
                    if(ny<0||ny>=m||nx<0||nx>=n)continue;
                    ans[ny][nx]='p';
                }
            }
        }
    }
    int ansn=0;
    for(int i = 1;i < m;++i) {
        for(int j = 0;j < n;++j) {

            if(ans[i][j]=='@')++ansn;
        }

    }
    cout<<ansn<<endl;
    return 0;
}



Measured memory_bytes: 3188
from collections import defaultdict


def main():
    n = int(input())
    l = list(map(int, input().split()))
    ans = 10 ** 20
    for x in range(-100, 101):
        ans = min(ans, sum([(x - a) ** 2 for a in l]))

    print(ans)

if __name__ == '__main__':
    main()


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}
typedef pair<ll, ll> pll;

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), b(n), c(n);
	rep(i, n) cin >>a[i];
	rep(i, n) cin >>b[i];
	rep(i, n) cin >>c[i];
	
	sort(all(a)); 
	sort(all(b)); 
	sort(all(c)); 
	ll ans = 0;
	
	rep(i, sz(b)){
		ll cr = lower_bound(all(a), b[i]) - a.begin();
		ll zr = upper_bound(all(c), b[i]) - c.begin();
		ans += cr * (n - zr);
		//dbg(n-zr,cr,b[i]);
	}
	
	cout << ans <<"\n";
	
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
    public class Main{
      public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        
        if(e-a <= k){
          System.out.println("Yay!");
        }else{
          System.out.println(":(");
        }
      }
    }

Measured memory_bytes: 23892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#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,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    string S, T;
    cin >> S >> T;

    vvi dp(3001,vi(3001,0));

    REP(s,S.length()) REP(t,T.length()) {
        if (S[s] == T[t]) chmax(dp[s+1][t+1], dp[s][t]+1);
        chmax(dp[s+1][t+1], dp[s+1][t]);
        chmax(dp[s+1][t+1], dp[s][t+1]);
    }

    string ans;
    int s = S.length();
    int t = T.length();

    while (s>0 and t>0){
        if      (dp[s][t] == dp[s-1][t]) s--;
        else if (dp[s][t] == dp[s][t-1]) t--;
        else {
            ans = S[s-1] + ans;
            s--;
            t--;
        }

    }

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

Measured memory_bytes: 35584
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  int judge=0;
  ll k;
  rep(i,1000) if(i*(i-1)/2==N) {judge=1; k=i; break;}
  if(!judge) {cout<<"No"<<'\n'; return 0;}
  else cout<<"Yes"<<'\n';
  
  vector<vector<ll>> S(k,vector<ll>(0));
  ll label=1;
  rep(i,k){
    for(int j=i+1;j<k;j++){
      S[i].push_back(label);
      S[j].push_back(label);
      label++;
    }
  }
  
  cout<<k<<'\n';
  rep(i,k){
    cout<<S[i].size();
    for(auto s:S[i]) cout<<" "<<s;
    cout<<'\n';
  }
  
  return 0;
}


Measured memory_bytes: 5096
use proconio::input;
use proconio::marker::Usize1;

fn main() {
  input! {
    N: usize,
    M: usize,
    mut H: [usize;N]
  }

  let mut map = vec![true;N];
  for _ in 0..M {
    input! {
      A: Usize1,
      B: Usize1
    }
    if *map.get(A).unwrap() {
      map[A] = H[A] > H[B];
    }

    if *map.get(B).unwrap() {
      map[B] = H[B] > H[A];
    }
  }
  
  let mut count = 0;
  for v in map {
    if v {
      count += 1;
    }
  }
  println!("{}", count);
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 998244353;

int main(){
  int n;
  cin >> n;
  int v[20], c[20];
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  int k[20];
  rep(i, n) k[i] = v[i]-c[i];
  int ans = 0;
  rep(i, n) ans += max(k[i], 0);
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

map<int,int> Map;
int i,j,k,l,n,m,x,p,f;

int main()
{
    scanf("%d%d",&n,&k);
    for (i=1;i<=k;i++)
    {
        scanf("%d",&x);
        Map[x]++;
    }
    for (i=n;i<=10000000;i++)
    {
        x=i;f=0;
        for (;x;x/=10)
        {
            p=x%10;
            if (Map[p]==1) f=1;
        }
        if (f==0)
        {
            printf("%d",i);
            return 0;
        }
    }
}


Measured memory_bytes: 256
let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

let int_of_digit c = int_of_char c - 48 (* 48 = int_of_char '0' *)

let sum_digits n =
  let s = string_of_int n in
  fold_int
    (fun sum i -> sum + int_of_digit s.[i])
    0
    (String.length s)

let solve n a b =
  fold_int
    (fun sum i ->
      let i = i + 1 in
      let d = sum_digits i in
      sum + if a <= d && d <= b then i else 0)
    0
    n

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  match read_ints () with
  | [n; a; b] -> solve n a b |> string_of_int |> print_endline
  | _ -> ()

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

int main()
{
    int n,k,i,j,ans,s;
    cin>>n>>k;
    int p[n];
    for (i = 0; i < n; i++) cin>>p[i];
    for (i = 0; i < n-1; i++)
    {
        for (j = i+1; j < n; j++)
        {
            if (p[i]>p[j])
            {
                s=p[i];
                p[i]=p[j];
                p[j]=s;
            }
        }
    }
    ans=0;
    for (i = 0; i < k; i++) ans+=p[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      if (4 * i + 7 * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	int min, max, hade;
};
P b[300];
int d, n,t[300];
vector<int>a[300];
int dp[300][300];
int solve(int i, int mae) {
	if (i == d) return 0;
	int sum = 0;
	for (int j = 0; j < a[i].size(); j++) {
		int res = mae - b[a[i][j]].hade;
		res = max(res, 0 - res);
		if (dp[i + 1][a[i][j]] != -1) {
			sum = max(sum, res + dp[i + 1][a[i][j]]);
		}
		else {
			dp[i + 1][a[i][j]] = solve(i + 1, b[a[i][j]].hade);
			sum = max(sum, dp[i + 1][a[i][j]] + res);
		}
	}
	return sum;
}
int main() {
	cin >> d >> n;
	for (int i = 0; i < d; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i].min >> b[i].max >> b[i].hade;
	}
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < n; j++) {
			if (b[j].min <= t[i] && b[j].max >= t[i]) {
				a[i].push_back(j);
			}
		}
	}
	for (int i = 0; i <= d; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = -1;
		}
	}
	int sum = 0;
	for (int i = 0; i < a[0].size(); i++) {
		if (dp[0][a[0][i]] != -1) {
			sum = max(sum, a[0][i] - dp[1][a[0][i]]);
		}
		else {
			sum = max(sum, dp[1][a[0][i]] = solve(1, b[a[0][i]].hade));
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALL(n) n.begin(),n.end()
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  ll N;
  cin>>N;
  vector<ll> a(N);
  vector<ll> b(N);
  vector<ll> n(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    n[i]=i+1;
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  ll A,B,cnt=1;
  do{
    if(n==a){
     // cout<<" ";
      A=cnt;
    }
    if(n==b){
      B=cnt;
    }
    cnt++;
    //cout<<n[0]<<n[1]<<n[2]<<endl;
  }while(next_permutation(ALL(n)));
  cout<<abs(A-B);
    
}


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

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

    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            sum += d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;


int main()
{

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

	int n, kkt; cin >> n >> kkt;
	vector<int> dp((1 << n), inf);
	dp[0] = 0;
	while (kkt--) {
		int a, b; cin >> a >> b;
		int S = 0;
		for (int i = 0; i < b; i++) {
			int c; cin >> c; c -= 1;
			S |= (1 << c);
		}
		for (int T = 0; T < (1 << n); T++) {
			int nT = S | T;
			chmin(dp[nT], dp[T] + a);
		}
	}
	if (dp[(1 << n) - 1] == inf) dp[(1 << n) - 1] = -1;
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

AB = sorted(AB, key=lambda x: x[1]-x[0]) # B-Aが小さい順にソート
AB = sorted(AB, key=lambda x: x[1])
t = 0

for i in range(N):
    if t <= AB[i][1] - AB[i][0]: # B-A以下のとき
        t += AB[i][0]
        continue
    else:
        print('No')
        break
else:
    if t <= AB[N-1][1]:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 61536
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var S = Read();
            var ans = 0;
            for (int i = 0; i < N - 2; i++)
            {
                if (S.Substring(i, 3) == "ABC") ans++;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7

def combInit(n):
    fact = [1]
    finv = [1]
    for i in range(1, n + 1):
        fact.append(fact[i - 1] * i % MOD)
        finv.append(pow(fact[i], MOD - 2, MOD))
    return [fact, finv]

def comb(n, k, f):
    if n < k:
        return 0
    elif n < 0 or k < 0:
        return 0
    else:
        return f[0][n] * (f[1][k] * f[1][n - k] % MOD) % MOD


def perm(n, r):
    return factorial(n) // factorial(r)


def gcb(a, b):
    if b == 0:
        return a
    else:
        return gcb(b, a % b)


def lcm(a, b):
    d = gcb(a, b)
    return int(a / d * b)


def surP(x):
    return x % MOD


def main():
    # ------ 入力 ------#
    h, w, a, b = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    f = combInit(h + w)
    res = 0
    for i in range(b, w):
        res += comb((h-1-a)+i, i, f) * comb((a-1)+(w-1-i), w-1-i, f)

    out = surP(res)
    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 24980
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int K = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int X = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int Y = Integer.parseInt(st.nextToken());

        int ans = 0;
        ans+=Math.min(N,K)*X;
        ans+=Math.max(0,N-K)*Y;

        System.out.println(ans);

    }
}

Measured memory_bytes: 21204
#include <iostream>

int main(void)
{
	while(true)
	{
		int a[10]={0},b[10]={0},n;
		for(int i=1; i<=4; i++)
		{
			if(!(std::cin >> n))
				return 0;
			a[n]=i;
		}
		for(int i=1; i<=4; i++)
		{
			if(!(std::cin >> n))
				return 0;
			b[n]=i;
		}

		int hit=0,blow=0;
		for(int i=0; i<=9; i++){
			if(b[i] == 0)
				continue;
			if(a[i] == b[i])
				hit++;
			else if(a[i]!=0)
				blow++;
		}
		std::cout << hit << " " << blow << std::endl;
	}
}

Measured memory_bytes: 1160
n = gets.to_i
as = gets.split.map(&:to_i)
count = 0

n.times do |i|
  minj = i

  (i...n).each do |j|
    minj = j if as[j] < as[minj]
  end

  count += 1 if i != minj
  as[i], as[minj] = as[minj], as[i]
end

puts as.join(' ')
p count



Measured memory_bytes: 6868
#include <iostream>

using namespace std;

typedef long long ll;

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

int main() {
    ios::sync_with_stdio(false);

    ll a, b;
    cin >> a >> b;

    ll d = gcd(a, b);

    int ans = 1;
    for (int i = 2; 1ll * i * i <= d; i++) {
        if (d % i == 0) {
            ans++;
            while (d % i == 0) {
                d /= i;
            }
        }
    }
    ans += d != 1;

    cout << ans << endl;

    return 0;
}


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

typedef long long int ll;
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  multiset<ll> ms;
  ll a, b, c;
  cin >> a >> b >> c;
  ms.insert(a);
  ms.insert(b);
  ms.insert(c);
  if (ms.count(5) == 2 && ms.count(7) == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j); i < (N);i++)
#define _rep(i,j,N) for(int i = (j); i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define ESP 1e-5
#define LL long long

const int maxn = 1005;

struct cake{
    LL x,y,z;
    cake(LL x = 0,LL y = 0,LL z = 0):x(x),y(y),z(z){;}
    bool operator<(cake &b) const{
        return (x+y+z > b.x + b.y + b.z);
    }
};

cake k[8][maxn];

int main()
{
    int N,M;
    scanf("%d %d",&N,&M);
    _for(i,0,N){
        LL x,y,z;
        scanf("%lld %lld %lld",&x,&y,&z);
        _for(j,0,7){
            LL xx = x,yy = y,zz = z;
            if(1 & j) xx = -xx;
            if((1<<1)&j) yy = -yy;
            if((2<<1)&j) zz = - zz;
            k[j][i] = cake(xx,yy,zz);
        }
    }
    LL ans = -1;

    _for(i,0,7){
        sort(k[i],k[i]+N);
        LL a = 0,b = 0,c = 0;
        _for(j,0,M){
            a += k[i][j].x;
            b += k[i][j].y;
            c += k[i][j].z;
        }
        ans = max(abs(a)+abs(b)+abs(c),ans);
    }

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


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

int main()
{
	string s;
	int q;
	cin >> s >> q;
	int t, f;
	bool flag = 0;
	string c;
	for (int i = 0; i < q; i++){
		cin >> t;
		if (t == 1){
			flag = !flag;
		} else {
			cin >> f >> c;
			if (flag and f == 1){
				s += c;
			} else if (flag and f == 2){
				s.insert(0, c);
			} else if (f == 1){
				s.insert(0, c);
			} else {
				s += c;
			}
		}
	}

	if (flag) reverse(s.begin(), s.end());
	cout << s << endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[123][223456];
//main
signed main(){
  int N,K;cin>>N>>K;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  memset(dp,0,sizeof(dp));
  for(int j=K+1;j<=200000;j++)dp[0][j]=1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=200000;j++){
      dp[i][j+1]+=dp[i-1][min(j+v[i-1]+1,100001LL)]-dp[i-1][j];
      dp[i][j+1]%=MOD;dp[i][j+1]+=MOD;dp[i][j+1]%=MOD;
      dp[i][j+2]+=dp[i][j+1];
      //cout<<dp[2][1]<<" "<<dp[1][3]<<" "<<dp[1][0]<<endl;
      //cout<<i<<" "<<j+1<<" "<<dp[i][j+1]<<endl;
    }
  }
  cout<<dp[N][1]<<endl;
}


Measured memory_bytes: 214912
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n,a,b;
ll h[100100];
int main(){
	cin>>n>>a>>b;
	REP(i,n)cin>>h[i];
	ll lb=-1,ub=1e9+1;
	while(ub-lb>1){
		ll mid=(lb+ub)/2;
		ll t=0;
		for(int i=0;i<n;i++){
			if(h[i]>mid*b){
				t+=((h[i]-mid*b+(a-b)-1)/(a-b));
			}
		}
		if(t<=mid){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	cout<<ub<<endl;
	return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.string, std.conv;
import std.math;

void main()
{
    for(;;)
    {
        immutable real x = readln().chomp().to!real();
        immutable real h = readln().chomp().to!real();
        if(x==0 && h==0) break;
        writefln("%.6f",x*x+x*sqrt(x*x+4*h*h));
    }
}

Measured memory_bytes: 1124
#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 INF 2e9
using namespace std;
typedef long long ll;
void inputVector(vector<int> * p, int a){ REP(i, a){ int input; cin >> input; p -> push_back(input); }}

int main(int argc, const char * argv[]) {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, c, cnt = 0; cin >> n >> m >> c;
  vector<int> b;
  inputVector(&b, m);
  REP(i, n) {
    int s = 0;
    REP(i, m) {
      int a; cin >> a;
      s += a * b[i];
    }
    s += c;
    if (s > 0) cnt++;
  }
  cout << cnt << '\n';
  return 0;
}

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

using namespace std;

typedef long long int64;
typedef vector<int,int> vec;
#define read(a) scanf("%d",&a)
#define printarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";

const int rmax = 1e5 + 10;
const int inf = INT_MAX;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if(abs(a-c) <= d)
        cout<<"Yes"<<endl;
    else if(abs(a-b) <= d and abs(b-c) <= d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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

int main() {
  cout.fill('0');
  int N,M;
  cin>>N>>M;
  vector<vector<long long>> A(N,vector<long long>(0));
  vector<long long> p(M);
  map<long long,pair<int,int>> m;
  for(int i=0;i<M;i++){
    long long a,b;
    cin>>a>>b;
    p.at(i)=b;
    A.at(a-1).push_back(b);
  }
  for(int i=0;i<N;i++){
    sort(A.at(i).begin(),A.at(i).end());
  }
  
  for(int i=0;i<N;i++){
    for(int j=0;j<A.at(i).size();j++){
      m[A.at(i).at(j)]={i+1,j+1};
    }
  }
  for(int i=0;i<M;i++){
    cout<<setw(6)<<m.at(p.at(i)).first<<setw(6)<<m.at(p.at(i)).second<<endl;
  }
  
      
  
}


Measured memory_bytes: 13952
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int D, G;
	cin >> D >> G;
	vector<int> p(D + 1, 0);
	vector<int> c(D + 1, 0);
	for (int i = 1; i <= D; i++) cin >> p[i] >> c[i];

	int MinAns = 1001;
	for (int i = 0; i < (1 << D); i++) {
		int Point = 0;
		int Ans = 0;
		int other = -1;
		for (int j = 1; j <= D; j++) {
			if ((i & 1 << (j - 1)) > 0) {
				Point += p[j] * j * 100 + c[j];
				Ans += p[j];
			}
			else other = j;
		}
		if (Point >= G) {
			MinAns = min(MinAns, Ans);
			continue;
		}
		if (G - Point > p[other] * 100 * other) continue;
		else {
			Ans += (G - Point + other * 100 - 1) / (other * 100);
			MinAns = min(MinAns, Ans);
		}
	}
	cout << MinAns;
}

Measured memory_bytes: 256
def make_indices_list(n):
  """
  Args:
    n (int)

  >>> make_indices_list(8):
  [7, 5, 3, 1, 0, 2, 4, 6]
  >>> make_indices_list(7):
  [6, 4, 2, 0, 1, 3, 5]
  """
  if n % 2 == 0:
    return list(range(n-1, 0, -2)) + list(range(0, n, 2))
  else:
    return list(range(n-1, -1, -2)) + list(range(1, n-1, 2))
    


n = int(input())
L = list(map(int, input().split()))

indices_list = make_indices_list(n)
for ind in indices_list:
  print(L[ind], end=' ')
print('')


Measured memory_bytes: 95060
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }



int main(){
  int x;
  cin >> x;
  cout << (x < 1200?"ABC":"ARC") << endl;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int w,h;

int isKakoi(int y,int x,char data[50][50]){
    bool bf=false,wf=false;
    int dy[]={-1,0,1,0};
    int dx[]={0,-1,0,1};
    bool visited[50][50]={};
    
    queue<pair<int,int> > que;
    
    que.push( pair<int,int>(y,x) );
    visited[y][x]=true;
    
    while(que.size()){
        int qff=que.front().first,qfs=que.front().second;
        rep(i,4){
            if( qff+dy[i]<h && qff+dy[i]>=0 && qfs+dx[i]<w && qfs+dx[i]>=0 && visited[ qff+dy[i] ][ qfs+dx[i] ]==false){
                if(data[qff+dy[i]][qfs+dx[i]]=='B')bf=true;
                else if(data[qff+dy[i]][qfs+dx[i]]=='W')wf=true;
                else{
                    que.push( pair<int,int>(qff+dy[i] , qfs+dx[i]) );
                    visited[ qff+dy[i] ][ qfs+dx[i] ]=true;
                }
            }
        }
        que.pop();
    }
    if(bf && wf)return -1;
    else if(bf)return 0;
    else if(wf)return 1;
    
    return 100;
}


int main(){
    while(cin>>w>>h){
        if(w==0 && h==0)break;
        
        char data[50][50];
        rep(i,h)cin>>data[i];
        
        
        int bk=0,wh=0;
        rep(i,h){
            rep(j,w){
                if(data[i][j]=='.'){
                    int res=isKakoi(i,j,data);
                    if( res==0 )wh++;
                    if( res==1 )bk++;
                }
            }
        }
        
        cout<<wh<<" "<<bk<<endl;
    }
    
    
    return 0;
}

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

#define mod 1000000007
#define INF (ll)9999999999999999

#define add emplace
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define exist(a, x) (a.find(x) != end(a))
#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i,a,b) for (int i = (int)a; i >= (int)b; --i)
#define loop(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;



int main() {
	int n, v, mx=-1, c0,c1;
	cin >> n;
	vi a;
	map<int,int> cnt;

	rep (i, n) {
		cin >> v;
		if (!cnt[v]) a.eb(v);
		cnt[v]++;
	}
	sort(all(a));
	n = len(a);

	for (auto k: cnt)
		mx = max(mx, k.second);

	if (n < 3) {
		c0 = cnt[a[0]];
		if (n == 1) return log(c0), 0;
		else if (n == 2) {
			c1 = cnt[a[1]];
			if (a[1]-a[0]==1) return log(c1+c0), 0;
			else return log(max(c0, c1)), 0;
		}
	}

	int w,x,y;
	rep (i, n-2) {
		w=a[i],x=a[i+1],y=a[i+2];
		if (w+1==x && x+1==y) mx = max(mx, cnt[w]+cnt[x]+cnt[y]);
		else if (w+1 == x) mx = max(mx, cnt[w]+cnt[x]);
		else if (x+1 == y) mx = max(mx, cnt[x]+cnt[y]);
	}

	log(mx);

	return 0;
}




Measured memory_bytes: 3452
#include <stdio.h>
int main()
{
  int x,a,b,eat;
  scanf("%d",&x); scanf("%d",&a); scanf("%d",&b);
  eat=b-a;
  if(b<=a) printf("delicious");
  else if(eat<=x) printf("safe");
  else printf("dangerous");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

VI parent, p, level;

ll get_parent(ll i) {
  if (parent[i] == i)
    return i;
  else
    return get_parent(parent[i]);
}

bool same(ll i, ll j) { return get_parent(i) == get_parent(j); }
void merge(ll i, ll j) {
  ll pi = get_parent(i);
  ll pj = get_parent(j);
  if (pi == pj) return;
  if (level[pi] < level[pj])
    parent[pi] = pj;
  else {
    parent[pj] = pi;
    if (level[pi] == level[pj]) level[pi]++;
  }
}

int main() {
  ll n, m, t1, t2;
  cin >> n >> m;

  REP(i, n) {
    cin >> t1;
    p.push_back(t1 - 1);
    level.push_back(0);
    parent.push_back(i);
  }
  REP(i, m) {
    cin >> t1 >> t2;
    t1--;
    t2--;
    merge(t1, t2);
  }
  ll count = 0;
  REP(i, n) if (same(i, p[i])) count++;
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 2912
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 1ll<<60
using namespace std;
const int N=2e5+100;
const int M=4e5+100;
const int mod=1e9+7;
LL arr[N];

int main() {
	LL k;

	while(cin>>k){
		
		cout<<50<<endl;
		LL tmp=k/50;
		for(int i=1;i<=50;i++)arr[i]=(LL)i+tmp-1;
		LL cnt=k%50;
		for(int i=1;i<=cnt;i++){
			
			for(int j=1;j<=50;j++){
				if(j==i){
					arr[j]+=50;
				}else{
					arr[j]-=1;
				}
			}
			
		}
		for(int i=1;i<=50;i++)cout<<arr[i]<<" ";
		cout<<endl;
	}
	return 0;
	
	


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, F[100][10], P[100][11];
    cin >> N;
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];

    int ans = -1000000000;
    FOR(i, 1, 1 << 10) {
        int profit = 0;
        REP(j, N) {
            int c = 0;
            REP(k, 10) if ((i >> k) & 1 && F[j][k]) c++;
            profit += P[j][c];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

int main() {
    int n, m;
    cin >> n >> m;
    if (m % n == 0) {
        cout << m / n << endl;
        return 0;
    }
    int upper = m / n;
    int ans = 1;
    int left;
    for (int i = upper; i >= 2; --i) {
        left = m - i * n;
        if (left % i == 0) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 0;
		int a = n / 500;
		sum += a * 1000;
		n = n - a * 500;
		int b = n / 5;
		sum += b * 5;
		System.out.println(sum);
	}
	
	}

Measured memory_bytes: 21712
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];

  vector<int> ans(n, -1);
  rep(i, m) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    if (n > 1 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == -1 && n > 1) ans[0] = 1;
  else if (ans[0] == -1 && n == 1) ans[0] = 0;
  FOR(i, 1, n) {
    if (ans[i] == -1) ans[i] = 0;
  }
  rep(i, n) cout << ans[i];
  cout << endl;


  
  return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vii dp;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s,t,ans; cin >> s >> t;
    dp.resize(3001, vi(3001));

    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < t.size(); ++j) {
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    
    int i = s.size()-1;
    int j = t.size()-1;
    while(i>=0&&j>=0) {
        if(dp[i+1][j+1]==dp[i][j+1]) {
            --i;
        }
        else if(dp[i+1][j+1]==dp[i+1][j]) {
            --j;
        }
        else {
            ans = s[i] + ans;
            --i;
            --j;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int main(){
    int a, b; cin >> a >> b;
    if(a > b){
        cout << "a > b" << endl;
    }
    else if(a < b){
        cout << "a < b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[3][3];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    }
    if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0])
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

const int INF=1e9+5;

void solve()
{
    int n;
    cin>>n;

    vi v(n);
    forn(i,n){
        cin>>v[i];
    }

    vi dp(n,INF);
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j:{i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],abs(v[i]-v[j])+dp[i]);
            }
        }
    }

    cout<<dp[n-1]<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<ll,P>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

vector<vector<P> > g;
vector<int> d;

void dijkstra(){
    fill(d.begin(), d.end(), IINF);
    d[0] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,0));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        int now = p.second;
        if(d[now] < p.first) continue;
        for(auto &e : g[now]){
            int nxt = e.first, c = e.second;
            if(d[nxt] > d[now] + c){
                d[nxt] = d[now] + c;
                que.push(P(d[nxt], nxt));
            }
        }
    }
}

int main(){
    int n, m, p;
    while(cin >> n >> m >> p, n){
        vector<int> a(p);
        g.clear();
        g.resize(n);
        d.resize(n);
        for(int i=0;i<m;i++){
            int u, v, c;
            cin >> u >> v >> c;
            g[u].push_back(P(v,c));
            g[v].push_back(P(u,c));
        }
        for(int i=0;i<p;i++){
            cin >> a[i];
        }
        dijkstra();
        vector<int> ord;
        vector<bool> used(n);
        vector<vector<double> > dp(2, vector<double>(n)); 
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(P(0,0));
        dp[0][0] = 1.0;
        while(!que.empty()){
            auto p = que.top();
            que.pop();
            int now = p.second;
            if(used[now]) continue;
            ord.push_back(now);
            used[now] = true;
            for(auto e : g[now]){
                int nxt = e.first , c = e.second;
                if(d[nxt] == d[now] + c){
                    que.push(P(d[nxt], nxt));
                    dp[0][nxt] += dp[0][now];
                }
            }
        }
        reverse(ord.begin(), ord.end());
        dp[1][n-1] = 1.0;
        for(auto now : ord){
            for(auto e : g[now]){
                int nxt = e.first, c = e.second;
                if(d[nxt]+c == d[now]){
                    dp[1][nxt] += dp[1][now];
                }
            }
        }
        for(int i=0;i<p;i++){
            printf("%.8lf\n", dp[0][a[i]]*dp[1][a[i]]/dp[0][n-1]);
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;

  vector<vector<bool>> G(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    --u;

    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      --v;

      G[u][v] = true;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << G[i][j];

      if (j != n - 1) cout << " ";
    }

    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>  
using namespace std;  
typedef long long ll;  
ll ans;  
int num[100010];  
int main(){  
    int n;  
    cin>>n;  
    for(int i=1;i<=n;i++){  
        scanf("%d",&num[i]);  
        if(num[i]==i) ans++;  
    }  
    if(!ans){  
        cout<<0<<endl;  
        return 0;  
    }  
    ans=0;  
    for(int i=1;i<=n;i++){  
        if(num[i]==i){  
            ans++;  
            swap(num[i],num[i+1]);  
        }  
    }  
    cout<<ans<<endl;  
}  

Measured memory_bytes: 640
using System;
class Program {
  static int sumDigits(int n) {
    int sum = 0;
    while (n > 0) {
      sum += n % 10;
      n = n / 10;
    }
    return sum;
  }
  static void Main(string[] args) {
    string[] values = Console.ReadLine().Split();
    int N = int.Parse(values[0]);
    int A = int.Parse(values[1]);
    int B = int.Parse(values[2]);

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
      int sum = sumDigits(i);
      if (A <= sum && sum <= B) ans += i;
    }

    Console.WriteLine(ans);    
  }
}


Measured memory_bytes: 11092
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
#define PB push_back
bool cmp(const pi &a,const pi &b){
    return a.S>b.S;
}
int main(){
    string s;
    pi temp;
    vector<pi> v;
    map<int,int> m;
    int now;
    while(getline(cin,s)){
        temp=MP(0,0);
        now=0;
        while(s[now]!=','){
            temp.F*=10;
            temp.F+=s[now++]-'0';
        }
        now++;
        while(now<s.size()){
            temp.S*=10;
            temp.S+=s[now++]-'0';
        }
        if(temp.F==0&&temp.S==0)break;
        else v.PB(temp);
    }
    sort(v.begin(),v.end(),cmp);
    now=1;
    m.insert(MP(v[0].F,now));
    for(int i=1;i<v.size();i++){
        if(v[i].S<v[i-1].S)now++;
        m.insert(MP(v[i].F,now));
    }
    while(cin>>now)printf("%d\n",m[now]);
}


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

using lint = long long int;
using pii = std::pair<int, int>;

using std::vector;
vector<int> ve;

int main(void) {
	int N;
	scanf("%d", &N);
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int temp;
		scanf("%d", &temp);
		ve.push_back(temp);
	}
	for (int i = 0; i < N - 1; i++) {
		if (ve[i] == i + 1) {
			std::swap(ve[i], ve[i + 1]);
			ans++;
		}
	}
	if (ve[N - 1] == N) {
		ans++;
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll N,M;

int main(){
    cin>>N>>M;
    if(N>=M/2)out(M/2);
    else{
        out(N+(M-2*N)/4);
    }

}


Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
ab = [tuple(int(x) for x in input().split()) for _ in range(n)]

ab.sort(reverse=True, key=itemgetter(1))

d = ab[0][1]

for a, b in ab:
    d = min(d, b)
    d -= a
    if d < 0:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 32048