akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#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 REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int X, Y;

// Mod begin
class Mod {
public:
  // 全部 mod p で考える。
  // Combを使うにはpが素数である必要がある。
  int p;
  vector<int> fact;
  Mod(int p) : p(p), fact{1} {}

  int Fact(int n) {
    if (n % p > fact.size() - 1) {
      int i = fact.size();
      fact.resize(n % p + 1);
      for (; i <= n % p; ++i) {
        fact[i] = (fact[i-1] * i) % p;
      }
    }
    return fact[n];
  }

  // n! = a * p^e の a mod p をreturnしeを変更で返す
  int ModFact(int n, int& e) {
    e = 0;
    if (n == 0) { return 1; }

    int res = ModFact(n / p, e);
    e += n / p;

    if ((n / p) % 2 == 0) {
      return (res * Fact(n % p)) % p;
    } else {
      return (res * (p - Fact(n % p))) % p;
    }
  };

  int Extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
      d = Extgcd(b, a % b, y, x);
      y -= (a / b) * x;
    } else {
      x = 1; y = 0;
    }
    return d;
  };

  // 一般的すぎるので繰り返し自乗法とかにしてもいいかも
  int Inv(int n) {
    int x, y;
    Extgcd(n, p, x, y);
    return ((p + x) % p) % p;
  };

  int Comb(int n, int k) {
    if (n < 0 || k < 0 || n < k) { return 0; }
    int e1, e2, e3;
    int a1 = ModFact(n, e1), a2 = ModFact(k, e2), a3 = ModFact(n - k, e3);
    if (e1 > e2 + e3) {
      return 0;
    } else {
      return (a1 * Inv((a2 * a3) % p)) % p;
    }
  };
};
// Mod end

int Ans() {
  if (Y > X) {
    int tmp = X;
    X = Y;
    Y = tmp;
  }
  // Xの方が大きいとしてよい

  int d = X - Y;
  // d回だけ(2,1)移動の回数が多い、残りは等しい回数

  // n: (3,3)移動の回数
  if ((Y-d)%3 != 0) { return 0; }
  int n = (Y-d)/3;

  // (2*n+d) C n mod MOD が答え
  Mod m(MOD);
  return m.Comb(2*n+d, n);
}

signed main() {
  cin >> X >> Y;

  auto ans = Ans();

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


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int w, h, n;
	cin >> w >> h >> n;
	vector<vector<int>> g(w, vector<int>(h));
	rep(i, w)rep(j, h) g[i][j] = 0;
	
	rep(i, n) {
		int x, y, a;
		cin >> x >> y >> a;
		x--; y--;
		if (a == 1) {
			rep(i, x + 1)rep(j, h) g[i][j] = 1;
		}
		if (a == 2) {
			for (int i = x + 1; i < w; ++i)rep(j, h) g[i][j] = 1;
		}
		if (a == 3) {
			rep(i, w)rep(j, y + 1) g[i][j] = 1;
		}
		if (a == 4) {
			rep(i, w)for (int j = y + 1; j < h; ++j) g[i][j] = 1;
		}
	}

	int ans = 0;
	rep(i, w)rep(j, h) {
		if (g[i][j] == 0) ans++;
	}
	

	dunk(ans);

	return 0;
}

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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

ll exp(ll m, ll n){
    if(n == 0) return 1;
    else if (n % 2 == 1) return (m * exp(m, n - 1)) % INF;
    else {
        ll tmp = exp(m, n/2);
        return tmp * tmp % INF;
    }
}


ll nCa(ll n, ll a){
    ll num = 1, den = 1;
    for(ll i = n - a + 1; i <= n; i++){
        num = num * i % INF;
    }
    for(ll i = 1; i <= a; i++){
        den = den * i % INF;
    }
    return num * exp(den, INF - 2) % INF;
}

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

    ll ans = (exp(2, N) - nCa(N, A)- nCa(N, B) - 1) % INF;
    if(ans < 0) ans += INF;
    cout << ans << endl;
}

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

int main() {
  int s1s2s3;

  cin >> s1s2s3;
  
  int A = s1s2s3 / 100;
  int A1 = s1s2s3 % 100;
  int B = A1 / 10;
  int B1 = A1 % 10;
  int C = B1 / 1;
     
  cout << A + B + C << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define slf(n) scanf("%lld",&n)
#define plf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,less<int> > q;
const int N=2e5+10;
const int mod=1e9+7;
int n,m;
int main()
{
	stf(n,m);
	if(n>=10||m>=10)cout<<"-1\n";
	else cout<<n*m<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string x;
    cin >> x;
    int fx=0;
    rep(i,x.size())fx+=(int)(x[i]-'0');
    cout <<  (stoi(x)%fx==0?"Yes":"No");
    
    
	return 0;
}

Measured memory_bytes: 3620
x = int(input())


i = 0
a, b = 0, 0
while i**5 < x:
    i += 1
mx = i
for k in range(2 * (mx + 1)):
    for j in range(-k, k + 1):
        if k**5 - j**5 == x:
            a, b = k, j
print(a, b)


Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    llint k,n;
    cin>>k>>n;
    vector<llint> v(n);
    REP(i,n){
        cin >> v[i];

    }
    llint result = inf;
    REP(i,n-1){
        result=min(result,k-abs(v[i]-v[(i+1)%n]));
    }
    result = min(result, k - (v[0] + (k - v[n - 1])));
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i*500 + 100*j + 50*k ==X:
        count +=1
print(count)

Measured memory_bytes: 9164
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;

void solve()
{
 double i,j=1,k,n,m=0,f,s1=0,x,c=1,t;
 cin>>n;
 n=n/3.0L;
 n=n*n*n;
 cout<<fixed<<setprecision(10)<<n;
}


 //}

    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
         //cin>>t;
        while(t--)
        solve();
    }


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  public static int N;
  public static boolean[][] graph;
  public static int ans = 0;

  public static void dfs(int now, int prv, boolean[] used) {
    boolean flag = true;
    for (boolean b : used) {
      flag &= b;
    }
    if (flag) {
      ans++;
      return;
    }
    for (int i = 0; i < N; i++) {
      if (i != now && i != prv && graph[now][i] && !used[i]) {
        boolean[] sub = used.clone();
        sub[i] = true;
        dfs(i, now, sub);
      }
    }
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    N = scanner.nextInt();
    int M = scanner.nextInt();
    graph = new boolean[N][N];
    boolean[] used = new boolean[N];
    used[0] = true;
    for (int i = 0; i < M; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      graph[a][b] = true;
      graph[b][a] = true;
    }
    dfs(0, 0, used);
    System.out.println(ans);
  }
}


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

int main()
{
	int N, a, x,s;
	x = 0;
	cin >> N;
	while (N > 0) {
		cin >> a;
		
		s = 0;
		for (int i = 2;i <= sqrt(a);i++) {
			if (a%i == 0) {
				s = 1;
				break;
			}
		}
		if (s==0)
			x++;
		N--;
	}
	cout << x << endl;
}

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

using namespace std;

int n,sum,mx,tmp;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>tmp;
		sum+=tmp;
		mx=max(mx,tmp);
	}
	if(2*mx<sum) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}
	

Measured memory_bytes: 256
line = gets
line.chomp!

/(\d+)\s*(\d+)\s*(\d+)/ =~ line
a = $1.to_i
b = $2.to_i
k = $3.to_i

if a < b then
  c = a
  a = b
  b = c
end

# 最大公約数
def gcd (m,n)
  r = m % n
  m1 = m
  n1 = n
  while r > 0
    m1 = n1
    n1 = r
    r = m1 % n1
  end
  return n1
end

c = gcd(a,b)

# 約数列挙
def divisors (n)
  array = []
  max = Math.sqrt(n).to_i
  for num in 1..max do
    if n%num == 0
      array.push(num)
      pair = n/num
      if (pair != num)
        array.push(pair)
      end
    end
  end
  return array.sort
end

print divisors(c)[-k]


Measured memory_bytes: 1788
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val input = readLine()!!.toLong()

    var result = 0L
    for (a in 1..input) {
        for (b in 1..input) {
            for (c in 1..input) {
                result += gcd(a, b, c)
            }
        }
    }
    println(result)
}

fun gcd(a: Long, b: Long, c: Long): Long {
    val minValue = min(a,b)
    val maxValue = max(a,b)

    val test = gcd(maxValue, minValue)

    val minValue2 = min(test, c)
    val maxValue2 = max(test, c)

    return gcd(maxValue2, minValue2)
}

fun gcd(higher: Long, lower: Long): Long {
    if (lower == 0L) {
        return higher
    }

    return gcd(lower, higher % lower)
}

Measured memory_bytes: 35668
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int t(char c){
  if (c == 'A')
    return 0;
  if (c == 'C')
    return 1;
  if (c == 'G')
    return 2;
  if (c == 'T')
    return 3;


  return 4;
}

char s(int a){
  if (a == 0)
    return 'A';
  if (a == 1)
    return 'C';
  if (a == 2)
    return 'G';
  if (a == 3)
    return 'T';

  return 'B';
}

bool ok(int a, int b, int c, int d){
  if (b == t('A') && c == t('G') && d == t('C'))
    return 0;
  if (b == t('G') && c == t('A') && d == t('C'))
    return 0;
  if (b == t('A') && c == t('C') && d == t('G'))
    return 0;
  if (a == t('A') && c == t('G') && d == t('C'))
    return 0;
  if (a == t('A') && b == t('G') && d == t('C'))
    return 0;

  return 1;
}

int main(void){
  ll n;
  cin >> n;
  
  int dp[n + 1][4][4][4] = {};
  for (int i = 0; i < 4; i++){
    for (int j = 0; j < 4; j++){
      for (int k = 0; k < 4; k++){
        string f = {s(i), s(j), s(k)}; 
        if (f != "AGC" && f != "GAC" && f != "ACG")
          dp[3][i][j][k]++;
      }
    }
  }

  for (int l = 3; l < n; l++){
    for (int i = 0; i < 4; i++){
      for (int j = 0; j < 4; j++){
        for (int k = 0; k < 4; k++){
          // mを後ろにつける
          for (int m = 0; m < 4; m++){
            if (ok(i, j, k, m))
              dp[l + 1][j][k][m] = (dp[l + 1][j][k][m] + dp[l][i][j][k]) % MOD;
          }
        }
      }
    }
  }

  ll res = 0;
  for (int i = 0; i < 4; i++){
    for (int j = 0; j < 4; j++){
      for (int k = 0; k < 4; k++){
        res = (res + dp[n][i][j][k]) % MOD;
      }
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
abcd = input()
n = 3

for i in range(2**n):
    num = []
    bi = format(i, '03b')
    for j in range(n):
        num.append(abcd[j])
        if bi[j] == '0':
            num.append('+')
        else:
            num.append('-')
    num.append(abcd[-1])
    calc = ''.join(num)
    if eval(calc) == 7:
        break

print(str(calc)+'=7')

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);

using namespace std;



ll x;
	vector <ll> v, t;


	bool check1(vector<ll> tmp) {
		
		for (int i = 0; i < x; i++) {
			if (tmp[i] != v[i]) return false;
		}

		return true;
	}
	bool check2(vector<ll> tmp) {

		for (int i = 0; i < x; i++) {
			if (tmp[i] != t[i]) return false;
		}

		return true;
	}


int main()
{
	MohamedMotaz;
	cin >> x;
	for (int i = 0; i < x; i++) {
		ll s; cin >> s; v.push_back(s);
	}
	for (int j = 0; j < x; j++) {
		ll s; cin >> s; t.push_back(s);
	}
	vector<ll> tmp;
	for (auto elem : v) {
		tmp.push_back(elem);
	}
	sort(tmp.begin(), tmp.end());
	ll counter = 0;
	ll a, b;
	do {
		counter++;
		if (check1(tmp)) a = counter;
		if (check2(tmp)) b = counter;
	} while (next_permutation(tmp.begin(), tmp.end()));

	cout << abs(a - b);
}





















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, K, ans;
    cin >> N >> K;
    vector<int> h(N);
    REP(int,i,0,N) cin >> h.at(i);
    vector<int> dp(N,INT_MAX);
    dp.at(0) = 0;
    REP(int,i,1,N){
        REP(int,j,1,K+1){
            if ( i - j < 0 ) break;
            else dp.at(i) = min(dp.at(i), abs(h.at(i) - h.at(i-j))+dp.at(i-j));
        }
    }
    //REP(int,i,0,N) cout << dp.at(i) << endl;
    cout << dp.at(N-1) << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(solve(A, B, K));

        sc.close();
    }

    static int solve(int A, int B, int K) {
        int count = 0;
        for (int i = Math.min(A, B);; --i) {
            if (A % i == 0 && B % i == 0) {
                ++count;
                if (count == K) {
                    return i;
                }
            }
        }
    }
}

Measured memory_bytes: 35536
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    int a,b;
    cin>>a>>b;

    cout<<6-a-b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::string S)
{
    if (S[0] == 'W' || S[2 * N - 1] == 'W')
    {
        cout << 0 << endl;
        return;
    }

    vector<int> LR(S.size());
    LR[0] = 1;
    int cntL = 1;
    int cntR = 0;
    for (int i = 1; i < S.size(); i++)
    {
        if (S[i - 1] == S[i])
        {
            if (LR[i - 1] == 0)
            {
                LR[i] = 1;
            }
            else
            {
                LR[i] = 0;
            }
            cntL++;
        }
        else
        {
            LR[i] = LR[i - 1];
            cntR++;
        }
    }
    // if(cntL != cntR){
    //     cout << 0 << endl;
    //     return;
    // }
    int L = 0;
    int R = 0;
    ll ans = 1;
    for (int i = 0; i < S.size(); i++)
    {
        if (LR[i] == 1)
        {
            L++;
        }
        else
        {
            ans *= L - R;
            ans %= MOD;
            R++;
        }
    }
    if(L!=R){
        cout << 0 << endl;
        return;
    }
    for (int i = 1; i <= N; i++)
    {
        ans *= i;
        ans %= MOD;
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 1536
n=int(input());
A=[int(input().replace(' ',''),2)for _ in[0]*n]
dp=[0]*2**n
dp[0]=1
for I in range(2**n-1):
    a=A[bin(I).count('1')]&~I
    for j in range(n):
        if a&1<<j:dp[I|1<<j]=(dp[I|1<<j]+dp[I])%(10**9+7)
print(dp[-1])

Measured memory_bytes: 58588
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct point
{
    int x,y;
};
point p[200005];
bool cmp(point a,point b)
{
    return a.y>b.y;
}
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        p[i].y=0;
    for(int i=1;i<=n;i++)
    {
        int c;
        scanf("%d",&c);
        p[c].x=c;
        p[c].y++;
    }
    sort(p+1,p+1+200000,cmp);
    long long sum=0;
    for(int i=1;i<=k;i++)
    {
        sum+=p[i].y;
    }
    cout<<n-sum<<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e6 + 5;

vector<int> adj[N];
int n, sub[N];
ll d[N], D;
map<ll, int> pos;

void no_answer() {
  puts("-1");
  exit(0);
}

void calc(int u, int p, int d = 0) {
  D += d; 
  for (int v : adj[u]) calc(v, u, d + 1);
}

void check(int u, int p, ll D) {
  if (D != d[u]) no_answer();
  for (int v : adj[u]) check(v, u, D + n - 2 * sub[v]);
}

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

  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 1);
  sort(ord.begin(), ord.end(), [](int i, int j) { return d[i] > d[j]; });

  for (int i = 0; i < n - 1; ++i) {
    int u = ord[i];
    ++sub[u];
    ll dp = d[u] - n + 2 * sub[u];
    if (!pos.count(dp)) no_answer();
    int p = pos[dp];
    sub[p] += sub[u];
    adj[p].push_back(u);
  }

  calc(ord[n - 1], 0);
  check(ord[n - 1], 0, D);

  for(int i = 1; i <= n; ++i) {
    for(int j : adj[i]) {
      printf("%d %d\n", i, j); 
    }
  }

  return 0;
}


Measured memory_bytes: 40340
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pair<P, int>> a(n);
    int p3 = 1;
    for (int i = 0; i < n; ++i) {
        int x, y, p;
        cin >> x >> y >> p;
        a[i] = { { x, y }, p };
        p3 *= 3;
    }
    vector<long long> ans(n + 1, 1LL << 60);
    vector<vector<int>> xmin(1 << n, vector<int>(n, M));
    vector<vector<int>> ymin(1 << n, vector<int>(n, M));
    for (int i = 0; i < (1 << n); i++) {
        vector<int> xs;
        xs.push_back(0);
        for (int j = 0; j < n; j++) {
            if (((i >> j) & 1) == 1) {
                xs.push_back(a[j].first.first);
            }
        }
        sort(xs.begin(), xs.end());
        for (int j = 0; j < n; j++)
        {
            auto k = lower_bound(xs.begin(), xs.end(), a[j].first.first);
            if (k != xs.end()) {
                xmin[i][j] = min(xmin[i][j], abs(a[j].first.first - *k));
            }
            if (k != xs.begin()) {
                --k;
                xmin[i][j] = min(xmin[i][j], abs(a[j].first.first - *k));
            }
        }
    }
    for (int i = 0; i < (1 << n); i++) {
        vector<int> ys;
        ys.push_back(0);
        for (int j = 0; j < n; j++) {
            if (((i >> j) & 1) == 1) {
                ys.push_back(a[j].first.second);
            }
        }
        sort(ys.begin(), ys.end());
        for (int j = 0; j < n; j++)
        {
            auto k = lower_bound(ys.begin(), ys.end(), a[j].first.second);
            if (k != ys.end()) {
                ymin[i][j] = min(ymin[i][j], abs(a[j].first.second - *k));
            }
            if (k != ys.begin()) {
                --k;
                ymin[i][j] = min(ymin[i][j], abs(a[j].first.second - *k));
            }
        }
    }
    for (int i = 0; i < p3; i++) {
        int c = 0;
        int mx = 0, my = 0;
        for (int j = 0, k = i; j < n; j++, k /= 3)
        {
            if (k % 3 == 1) {
                ++c;
                mx ^= 1 << j;
            }
            if (k % 3 == 2) {
                ++c;
                my ^= 1 << j;
            }
        }
        long long sum = 0;
        for (int j = 0; j < n; j++)
        {
            sum += min(xmin[mx][j], ymin[my][j]) * (long long)a[j].second;
        }
        ans[c] = min(ans[c], sum);
    }
    for (auto& i : ans) {
        cout << i << '\n';
    }
    return 0;
}


Measured memory_bytes: 9780
import java.io.*;
import java.util.*;
public class Main
{
    static PrintWriter out=new PrintWriter((System.out));
    public static void main(String args[])throws IOException
    {
        Reader sc=new Reader();
        int k=sc.nextInt();
        String s=sc.nextLine();
        if(s.length()<=k)
        {
            out.println(s);
        }
        else
        {
            out.println(s.substring(0,k)+"...");
        }
        out.close();
    }

    static class Reader 
    { 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        public String next()
        {
            while(!st.hasMoreTokens())
            {
                try
                {
                    st=new StringTokenizer(br.readLine());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=br.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            st=new StringTokenizer(next);
            return true;
        }
    } 
}

Measured memory_bytes: 36476
#include <iostream>
#include <algorithm>
#include <stdio.h>
#define max(x,y) (x)>(y)?(x):(y)
using namespace std;
const int maxn=1e5+10;
const int maxx=1e13+10;
int x[maxn];
int y[maxn];
int t[maxn];
int n;
int dis(int i)
{
    int disx=x[i]-x[i-1];
    int disy=y[i]-y[i-1];
    if(disx<=0) disx=-disx;
    if(disy<=0) disy=-disy;
    int diss=disx+disy;
    if(t[i]-t[i-1]<diss) return 0;
    else if(t[i]-t[i-1]==diss) return 1;
    else 
    {
        if((t[i]-t[i-1]-diss)%2==0) return 1;
        else return 0;
    }
}
int main()
{
	scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d%d",&t[i],&x[i],&y[i]);
    t[0]=x[0]=y[0]=0;
    int flag=1; 
    for(int i=1;i<=n;i++)
    {
        if(dis(i)==1) continue;
        else 
        {
            flag=0; break;
        }
    }
    if(flag==1) printf("Yes\n");
    else printf("No\n" );
}

Measured memory_bytes: 1408
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
  int n;
  cin >> n;
  
  int max = 0;
  int max_i = n;
  for (int i = n; i > 0; -- i)
  {
    int tmp = i;
    int times = 0;
    for (; tmp % 2 == 0; tmp /= 2)
      times ++;
    if (times > max)
    {
      max = times;
      max_i = i;
    }
  }
  
  cout << max_i << endl;
  
  return 0;
}

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

typedef pair<int,int> P;

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll i = 0; i < n; ++i){
        cin >> v[i];
        if (v[i] == 0){
            cout << 0 << "\n";
            return 0;
        }
    }

    ll res = 1;
    for (ll i = 0; i < n; ++i){
        if (v[i] <= 1000000000000000000 / res){
            res *= v[i];
        }else{
            res = -1;
            break;
        }
    }
    cout << res << "\n";
}

Measured memory_bytes: 4000
N = int(input())
# print(N)
n = N
digit = 0
while n > 0:
    n //= 10
    digit += 1

# print(digit)

ans = 0
for i in range(digit - 1):
    if i % 2 == 0:
        ans += (10**(i + 1) - 10**i)

if digit % 2 == 1:
    ans += N + 1 - (10**(digit - 1))
print(ans)


Measured memory_bytes: 38384
def b(N, s):
    v = sum(s)
    for i in range(N, 0, -1):
        if v % 10 == 0:
            if s[i-1] % 10:
                v -= s[i-1]
            continue
        else:
            return v
    return 0
    
N = int(input())
s = []

for _ in range(N):
    s.append(int(input()))
    
s.sort(key=lambda x:-x)

print(b(N, s))

Measured memory_bytes: 3064
import sys
x = []
for line in sys.stdin:
    h,w = line.split()
    h,w = int(h), int(w)
    if h == 0 and w== 0: break
    x.append([h,w])

for e in x:
    h, w = e
    s1 = '.#' * ((w+1)/2)
    s2 = '#.' * ((w+1)/2)
    for j in range(h):
        if (j & 1)==0: print s2[:w]
        else: print s1[:w]
    print
    

Measured memory_bytes: 4236
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int prev = n;
    int cnt = 2;
    if (n == 1 or n == 2 or n == 4) {
        cout << 4 << '\n';
        return 0;
    }
    while (true) {
        int value;
        if (prev % 2 == 0) value = prev/2;
        else value = 3*prev + 1;
        if (value == 4 or value == 2 or value == 1) {
            cout << cnt + 3 << '\n';
            break;
        }
        prev = value;
        cnt++;
    }
   
    return 0;
}

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

const ll MOD = 1000000007;

void f(ll &a, ll b) {
    a = (a + b) % MOD;
}

int main() {
    string S;
    cin >> S;

    vector<vector<ll>> dp(S.size() + 1, vector<ll>(4));
    dp[0][0] = 1;

    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '?') {
            f(dp[i + 1][0], 3 * dp[i][0]);
            f(dp[i + 1][1], 3 * dp[i][1]);
            f(dp[i + 1][2], 3 * dp[i][2]);
            f(dp[i + 1][3], 3 * dp[i][3]);
        } else {
            f(dp[i + 1][0], dp[i][0]);
            f(dp[i + 1][1], dp[i][1]);
            f(dp[i + 1][2], dp[i][2]);
            f(dp[i + 1][3], dp[i][3]);
        }

        if (S.at(i) == 'A') {
            f(dp[i + 1][1], dp[i][0]);
        } else if (S.at(i) == 'B') {
            f(dp[i + 1][2], dp[i][1]);
        } else if (S.at(i) == 'C') {
            f(dp[i + 1][3], dp[i][2]);
        } else if (S.at(i) == '?') {
            f(dp[i + 1][1], dp[i][0]);
            f(dp[i + 1][2], dp[i][1]);
            f(dp[i + 1][3], dp[i][2]);
        }
    }

    cout << dp[S.size()][3] << endl;
}

Measured memory_bytes: 10356
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a[i])
	}

	v := make([]bool, n+1)

	next := 1
	cnt := 1
	for {
		v[next] = true
		next = a[next]
		if next == 2 {
			break
		}
		if v[next] {
			break
		}
		cnt++
	}

	if next != 2 {
		fmt.Println(-1)
		return
	}

	fmt.Println(cnt)
}

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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var d = new Dictionary<string, int>();
            var q = new Queue<string>();
            var s = Console.ReadLine().Trim();
            if (s == "0") break;
            var sL = s.Length;
            if (IsSame(s)) { Console.WriteLine(0); goto next; }
            q.Enqueue(s); d[s] = 1;
            Console.WriteLine(goBfs(d, q, sL));
            next:;
        }
    }
    public static string goBfs(Dictionary<string, int> d, Queue<string> q, int sL)
    {
        while (true)
        {
            if (q.Count() == 0) return "NA";
            var s = q.Dequeue();
            var count = d[s];
            for (int i = 0; i <= sL - 2; i++)
            {
                var ss = s.Substring(i, 2);
                if (ss[0] != ss[1])
                {
                    var ta = changeColor(s, i, ss);
                    if (IsSame(ta)) return count.ToString();
                    if (!d.ContainsKey(ta)) { d[ta] = count + 1; q.Enqueue(ta); }
                }
            }
        }
    }
    public static bool IsSame(string s)
    {
        var c = new string[] { "r", "g", "b" };
        foreach (var x in c)
            if (s.Replace(x, "").Length == 0) return true;
        return false;
    }
    public static string changeColor(string s, int i, string t)
    {
        string a;
        if (t == "rg" | t == "gr") a = "bb";
        else if (t == "gb" | t == "bg") a = "rr";
        else a = "gg";
        return s.Substring(0, i) + a + s.Substring(i + 2);
    }
}

Measured memory_bytes: 11712
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#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)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("a.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int a, p;
    cin >> a >> p;

    cout << (a*3 + p) / 2;

    return 0;
}

/*
  - 1e9 : 10^9
  - vector
    vector<int> A(N);
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int A[N], B[N], C[N];
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>B[i];
  for(int i=0;i<N-1;++i) cin>>C[i];
  int ans = 0;
  for(int i=0;i<N;++i) {
    ans += B[A[i]-1];
    if(i>0) {
      if(A[i]==A[i-1]+1) ans += C[A[i-1]-1];
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const ll inf = 1e18;
int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}



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

struct Node {
	int length{-1};
	std::list<int> edges;
};

int dfs(int);
std::vector<Node> graph;

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	graph.resize(n);
	for (int i{}; i < m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		graph[x].edges.push_back(y);
	}
	int max{};
	for (int i{}; i < n; i++)
		max = std::max(max, dfs(i));
	printf("%d\n", max);

	return 0;
}

int dfs(int index)
{
	int& length{graph[index].length};
	if (length >= 0) return length;
	length = 0;
	for (auto& e: graph[index].edges)
		length = std::max(length, dfs(e) + 1);
	return length;
}

Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {
	static int N;
	static int ans;

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

		N = sc.nextInt();

		dfs(0);

		System.out.println(ans);
	}

	static void dfs(long x) {
		if (x > N) {	//Nを超えたらダメ
			return;
		}

		if (check(x)) {		//3, 5, 7を含んでいるかを確認
			ans++;
		}

		if (x <= 1000000000) {
			dfs(10 * x + 3);
			dfs(10 * x + 5);
			dfs(10 * x + 7);
		}
	}

	static boolean check(long x) {
		String s = String.valueOf(x);
		if (s.contains("3") && s.contains("5") && s.contains("7")) {
			return true;
		} else {
			return false;
		}
	}
}

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

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

        rep(i,n){
            rep(j,m){
                cin >> a.at(i).at(j);
            }
        }

        int ans =0;

            rep(i,n){
                int sum=0;
                 rep(j,m){
                      sum += b.at(j)*a.at(i).at(j);
                    
                 } 
                 if(sum+c>0){
                     ans++;
                 }
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 3580
import sys
import math

mat = list(sys.stdin.readline().strip())

odd = 0
even = 0
for i, x in enumerate(mat):
    flg = i % 2
    if flg:
        if int(x) == 1:
            even += 1
        else:
            odd += 1
    else:
        if int(x) == 1:
            odd += 1
        else:
            even += 1

print(min(odd, even))


Measured memory_bytes: 3956
$<.gets
given = [nil] + $<.gets.split.map(&:to_i)
a = nil

given.drop(1).each_with_index do |key, i|
  j = i + 1
  str = "node #{j}: key = #{key}, "
  str += "parent key = #{a}, " if (a = given[j / 2])
  str += "left key = #{a}, "   if (a = given[j * 2])
  str += "right key = #{a}, "  if (a = given[j * 2 + 1])
  puts str
end


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  for (int i = 0, a; i < n; ++i) {
    cin >> a;
    if (a & 1) continue;
    if (a % 3 && a % 5) {
      cout << "DENIED\n";
      return 0;
    }
  }
  cout << "APPROVED\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();
        int max = P;
        if(max < R){
            max = R;
        }
        if(max < Q){
            max = Q;
        }
        System.out.println(P + Q + R - max);
        
    }
}


Measured memory_bytes: 21844
import math


class FenwickTree:
    def __init__(self, a_list, f, default):
        # 0-indexed
        self.N = len(a_list)
        self.bit = a_list[:]
        self.f = f
        self.default = default
        for _ in range(self.N, 1 << (math.ceil(math.log(self.N, 2)))):
            self.bit.append(self.default)
        for i in range(self.N - 1):
            self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i])

    def update(self, i, val):
        while i < self.N:
            self.bit[i] = self.f(self.bit[i], val)
            i |= i + 1

    def query(self, n):
        # [0, n]
        ret = 0
        while n >= 0:
            ret = self.f(ret, self.bit[n])
            n = (n & (n + 1)) - 1
        return ret


N = int(input())
X = [int(x) for x in input().split()]
dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0)
for x, i in sorted((x, i) for i, x in enumerate(X)):
    dp.update(i, dp.query(i) + x)
print(N * (N + 1) // 2 - dp.query(N - 1))

Measured memory_bytes: 27748
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  cin>>N>>H;
  cout<<(N*H/gcd(N,H));
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){    
	int a[100];    
	int n = 0;    
	int i = 0;              
	scanf("%d",&n);    
	for(i = 0;i < n;i++){        
		scanf("%d",&a[i]);    }         
	for(i = 0;i < n;i++){        
		if(i < n -1){            
			printf("%d ",a[n-1-i]);        }else
		{            printf("%d\n",a[n-1-i]);        
			}    
	}                  
	return 0;
} 

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <climits>

typedef long long ll;
using namespace std;

int main(){

	ll z;

	while(cin>>z, z){
			
		ll mn = LLONG_MAX;

		for(ll x=1; x*x*x<z*z*z; ++x){
			for(ll y=1; x*x*x + y*y*y < z*z*z; ++y){
				
				if( z*z*z - x*x*x - y*y*y < mn){
					mn =  z*z*z - x*x*x - y*y*y;
				}
			}
		}

		cout << mn << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{s:chars};
    let mut map = HashMap::new();
    for ch in s.iter() {
        match map.insert(ch, true) {
            Some(_v) => {
                println!("no");
                return ();
            },
            None => continue,
        }
    }
    println!("yes");
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    int ans = 0, curr = 1;

    while(N--)
    {
        int x;
        cin >> x;

        if(x == curr)
            curr++;
        else
            ans++;
    }

    if(curr == 1)
        ans = -1;
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c;
    scanf("%lld %lld %lld",&a,&b,&c);
    if(b<c)
    {
        ll tmp=a+b;
        //cout<<tmp<<endl;
        ll s=c-tmp;
        if(s<0)
            cout<<0<<endl;
        else
            cout<<s<<endl;
    }
    else
    {
        ll tmp=c+a;
        //cout<<tmp<<endl;
        ll s=b-tmp;
        if(s<0)
            cout<<0<<endl;
        else
            cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,Y,x,y,z,t=0;
  cin >> N >> Y;
  for (int i=0;i<N+1;i++) {
    for (int I=0;I<N-i+1;I++) {
      if (10000*i+5000*I+1000*(N-i-I)==Y){
        x=i; y=I; z=N-i-I; t=1; break;
      }
    }
  }
  if (t==0) cout << -1 << " " << -1 << " " << -1 << endl;
  if (t==1) cout << x << " " << y << " " << z << endl;
}

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

void printArray(int array[], int length) {
    for (int ixArray = 0; ixArray < length; ixArray++) {
        if (ixArray != 0) printf(" ");
        printf("%d", array[ixArray]);
    }
}

int bubbleSort(int array[], int length) {
    int swapCount = 0;
    int temp;
    
    for (int i = 0; i < length; i++)
        for (int j = length - 1; j > i; j--)
            if (array[j] < array[j-1]) {
                temp = array[j];
                array[j] = array[j-1];
                array[j-1] = temp;
                swapCount++;
            }
    
    return swapCount;
}

int main(int argc, char** argv) {
    int length;
    scanf("%d", &length);
    
    const int nxArray = length;
    int array[nxArray];
    for (int ixArray = 0; ixArray < nxArray; ixArray++)
        scanf("%d", &array[ixArray]);

//    for (int ixArray = 0; ixArray < nxArray; ixArray++) {
//        if (ixArray != 0) printf(" ");
//        printf("%d", array[ixArray]);
//    }
    
    int nos = bubbleSort(array, nxArray);
    
    printArray(array, nxArray);
    printf("\n");
    printf("%d\n", nos);
    
    

    return (EXIT_SUCCESS);
}




Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  ll ans = b - (b/c + b/d - b/(c/__gcd(c, d)*d));
  ans -= a - (a/c + a/d - a/(c/__gcd(c, d)*d));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
a,b,h,m=map(int,input().split())

tan=30*h+0.5*m
cho=6*m
import math

kaku1=360+tan-cho
kaku2=tan-cho
x=min(kaku1,kaku2)
x=math.radians(x)
ccos=math.cos(x)
cc=a**2+b**2-2*a*b*ccos

print(math.sqrt(cc))


Measured memory_bytes: 9572