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

vector<int> list1[MAX_SIZE];

int recurse(int i, int n, vector<int> &dp)
{

    if(dp[i] != -1) return dp[i];
    else
    {
        int max1 = 0;
        // for (int k = 1; k <= n; k++)
        // {
        //     if(mat[k][i] == 1)
        //     {
        //         flag = 1;
        //         max1 = max(recurse(k,n,mat,dp)+1,max1);
        //     }
        // }
        int sz = list1[i].size();
        for (int j = 0; j < sz; j++)
        {
            max1 = max(recurse(list1[i][j],n,dp)+1,max1);
        }
        return dp[i] = max1;
        
    }
}

int main(int argc, char const *argv[])
{
    int n , m;
    cin >>n >> m;
    int t1 ,t2;
    vector<int> temp;
    vector<int> dp(n+1,-1); //denotes the max length to this vertex
    
    for (int i = 0; i < m; i++)
    {
        cin >> t1 >> t2;
        list1[t2].push_back(t1);
    }

    for (int i = 1; i <= n; i++)
    {
        dp[i] = recurse(i,n,dp);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = max(ans,dp[i]);
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 16448
#106_D
N,M,Q=map(int,input().split())
S=[[0 for _ in range(N+1)] for _ in  range(N+1)]
for _ in range(M):
    L,R=map(int,input().split())
    S[L][R]+=1

for i in range(1,N+1):
    for j in range(1,N+1):
        S[i][j]+=S[i-1][j]
for i in range(1,N+1):        
    for j in range(1,N+1):
        S[i][j]+=S[i][j-1]


for _ in range(Q):
    p,q=map(int,input().split())
    print(S[q][q]-S[p-1][q]-S[q][p-1]+S[p-1][p-1])

Measured memory_bytes: 15072
import numpy as np

A = np.array([[int(val) for val in input().split(" ")] for i in range(3)])
N = int(input())
b = np.array([int(input()) for i in range(N)])

A_ = np.zeros_like(A)
for bi in b:
    row, col = np.where(A == bi)
    if row.size and col.size:
        A_[row[0]][col[0]] = 1

ans1 = sum(np.sum(A_, axis=0) == 3)
ans2 = sum(np.sum(A_, axis=1) == 3)
ans3 = (sum([A_[i,i] for i in range(3)]) == 3).astype(int)
ans4 = (sum([A_[i,2-i] for i in range(3)]) == 3).astype(int)
if ans1 or ans2 or ans3 or ans4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14552
#include<stdio.h>
int main()
{
    int a, b, c, k, n1, n2, sum;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if(a>=k) sum=k;
    else{
        if(b>=k-a) sum=a;
        else{
            sum=a-(k-(a+b));
        }
    }
    printf("%d", sum);
    return 0;
}



Measured memory_bytes: 1700
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2104
# -*- coding: utf-8 -*-
from sys import stdin
import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


A, B = _li()

print((B - 1 + A - 2) // (A-1))


Measured memory_bytes: 3060
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, s.length())) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

long long calcGcd(long long a, long long b) {
    // a > bにする
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法*/
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main() {
    long long K;
    cin >> K;

    //  Kが7の倍数ならばL = 9K/7, そうでなければL = 9Kと定義し
    // 10^i をLで割った余りが1であるような最小の正の整数iを求める
    // オイラーの定理より10とLが互いに素であれば必ず見つかる

    // Lで割った余りをとる演算は10倍するごとに行う

    long long L;

    // Lの定義
    if (K % 7 == 0) {
        L = 9 * K / 7;
    } else if (K % 7 != 0) {
        L = 9 * K;
    };

    // 10とLが互いに素ではない場合
    if (calcGcd(L, 10) != 1) {
        cout << "-1" << endl;
        return 0;
    }

    // 互いに素であるとき必ず見つかる
    long long count = 0;
    long long reminder = 1;
    while (true) {
        count++;
        reminder = (reminder * 10) % L;

        if (reminder == 1) break;
    }
    cout << count << endl;
}


Measured memory_bytes: 3644
using System;

namespace ABC119_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = DateTime.Parse(Console.ReadLine());
            var target = DateTime.Parse("2019/04/30");
            Console.WriteLine(s > target ? "TBD" : "Heisei");
        }

    }
}


Measured memory_bytes: 11744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();
		String strArray[] = str.split(" ", 0);
		int num[] = new int[strArray.length];

		for(int i=0; i<strArray.length; i++){
			num[i] = Integer.parseInt(strArray[i]);
		}
		for(int s=0; s<num.length; s++){
			for(int t=s+1; t<num.length; t++){
				if(num[t] < num[s]){
					int tmp = num[t];
					num[t] = num[s];
					num[s] = tmp;
				}
			}
		}
		System.out.println(num[0] + " " + num[1] + " " + num[2]);
	}
}

Measured memory_bytes: 16896
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
		t--;
		t %= k;
	}
	vector<int> ps(n + 1);
	for (int i = 0; i < n; i++) {
		ps[i + 1] = (ps[i] + a[i]) % k;
	}
	map<int, int> lol;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i >= k) {
			lol[ps[i - k]]--;
		}
		ans += lol[ps[i]];
		lol[ps[i]]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15872
#include <stdio.h>
int n, ans;
int p[20];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", p + i);
	}
	for (int i = 1; i < n - 1; i++) {
		if (p[i - 1] < p[i] && p[i] < p[i + 1])ans++;
		if (p[i] < p[i - 1] && p[i + 1] < p[i])ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		int n = sc.nextInt();
		long c = sc.nextLong();

		long[] x = new long[n + 1];
		long[] v = new long[n + 1];
		for (int i = 1; i <= n; i++) {
			x[i] = sc.nextLong();
			v[i] = sc.nextLong();
		}

		long[] sum = new long[n + 1];
		long[] a = new long[n + 1];
		long[] b = new long[n + 2];
		for (int i = 1; i <= n; i++) {
			sum[i] = sum[i - 1] + v[i];
			a[i] = Math.max(a[i - 1], sum[i] - x[i]);
		}

		b[n] = Math.max(0, v[n] - (c - x[n]));
		for (int i = n - 1; i > 0; i--) {
			b[i] = Math.max(b[i + 1], sum[n] - sum[i - 1] - (c - x[i]));
		}

		long answer = Math.max(a[n], b[1]);
		for (int i = 1; i <= n; i++) {
			answer = Math.max(answer, Math.max(
					sum[i] - 2 * x[i] + b[i + 1],
					sum[n] - sum[i - 1] - 2 * (c - x[i]) + a[i - 1]
			));
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 85568
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}

void solve(long N, int K, vector<long> h) {
  vector<long> cost(N, numeric_limits<long>::max());

  cost[0] = 0;
  REP(i, N) {
    REP(j, K) {
      if (i + j >= N)
	continue;
      chmin(cost[i + j + 1], cost[i] + abs(h[i] - h[i + j + 1]));
    }
  }
  cout << cost[N - 1] << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  int K;
  cin >> N >> K;
  vector<long> h(N);
  REP(i, N)
    cin >> h[i];

  solve(N, K, move(h));

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    n=n%k;
    while(n>abs(n-k)){
        n=abs(n-k);
    }
    cout<<n<<endl;
return 0;
}








Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize
    }

    let mut min_digits = 100;
    for i in 1..=(n as f64).sqrt() as usize {
        if n % i == 0 {
            let a_digits = ((i as f64).log10() as usize) + 1;
            let b_digits = (((n / i) as f64).log10() as usize) + 1;
            min_digits = min_digits.min(a_digits.max(b_digits));
        }
    }
    println!("{}", min_digits);
}


Measured memory_bytes: 2784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool IsSubsequence(string s, string t) {
  int j = 0;
  for (int i = 0; i < s.size(); i++) {
    while (j < t.size() && s[i] != t[j]) {
      j++;
    }
    if (j == t.size()) {
      return false;
    }
    j++;
  }

  return true;
}

int main() {
  string s, t;

  cin >> s >> t;

  string a, b;

  for (int i = 0; i < s.size(); i += 2) {
    a += s[i];
  }
  
  for (int i = 1; i < s.size(); i += 2) {
    b += s[i];
  }

  if (IsSubsequence(a, t) || IsSubsequence(b, t)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3172
#include<cstdio>
#include<algorithm>
#include<iostream>
#define N 200005
using namespace std;
int n,q,m;
long long Q,V[N],ans[N],a[N];
void CL(long long x,long long v)
{
	int P;
	P=upper_bound(a+1,a+m+1,x)-a-1;
	if (x<a[1])
	{
		ans[1]+=v;
		ans[x+1]-=v;
		return;
	}
	V[P]+=v*(x/a[P]);
	CL(x%a[P],v);
}
int main()
{
	scanf("%d%d",&n,&q);
	m++;
	a[m]=n;
	for (int i=1;i<=q;i++)
	{
		scanf("%lld",&Q);
		while (Q<=a[m])
			m--;
		a[++m]=Q;
	}
	V[m]=1;
	for (int i=m;i>1;i--)
	{
		V[i-1]+=V[i]*(a[i]/a[i-1]);
		CL(a[i]%a[i-1],V[i]);
	}
	ans[0]=0;
	ans[1]+=V[1];
	ans[a[1]+1]-=V[1];
	for (int i=1;i<=n;i++)
	{
		ans[i]+=ans[i-1];
		printf("%lld\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 6176
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	vector<double> l(n), a(n), b(n);
	for(int i = 0; i < n; ++i)
		scanf("%lf %lf %lf", &l[i], &a[i], &b[i]);

	vector<vector<double> > dist(n, vector<double>(n));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			const double dl = l[i] - l[j], da = a[i] - a[j], db = b[i] - b[j];
			dist[i][j] = dl * dl + da * da + db * db;
		}
	}

	double ans = 0.0;
	for(int i = 0; i < (1 << n); ++i) {
		if(__builtin_popcount(i) != m)
			continue;

		double tmp = 0.0;
		for(int j = 0; j < n; ++j)
			if(i & (1 << j))
				for(int k = j + 1; k < n; ++k)
					if(i & (1 << k))
						tmp += dist[j][k];


		chmax(ans, tmp);
	}

	printf("%.20lf\n", ans);

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1124
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

#define EPS 1e-9

double dist(int x, int y)
{
	return sqrt(x * x + y * y);
}

double angle(int x, int y)
{
	return atan2((double)(x), (double)(y));
}

int main()
{
	int x0, x1, y0, y1, x2, y2, q;

	cin >> x0 >> y0 >> x1 >> y1 >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> x2 >> y2;

		int ax = x1 - x0;
		int ay = y1 - y0;
		int bx = x2 - x0;
		int by = y2 - y0;

		double br = dist(bx, by);
		double cr = dist(bx, by);

		double at = angle(ay, ax);
		double bt = angle(by, bx);

		double ct = bt - (bt - at) * 2;

		double cx = x0 + cr * cos(ct);
		double cy = y0 + cr * sin(ct);

		if (cx < -EPS || EPS < cx)
		{
			cout << setprecision(15) << cx << ' ';
		}
		else
		{
			cout << 0 << ' ';
		}

		if (cy < -EPS || EPS < cy)
		{
			cout << setprecision(15) << cy << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}

	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 1000 + 5;
const int M = 1000 + 5;
const int MOD = 1e9 + 7;

char g[N][M];
ll dp[N][M];

int main() { 
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> g[i][j];
        }
    }
    dp[1][1] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (g[i][j] == '#') continue;
            (dp[i][j] += (dp[i - 1][j] + dp[i][j - 1])) %= MOD;
        }
    }
    cout << dp[n][m] << '\n';
}


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

using namespace std;

int k, N, L, phi[500009];
char sir[500009];
bool ok[500009];

void DoKmp ()
{
    k = 0;
    for (int i=2; i<=N; i++)
    {
        while (k && sir[k + 1] != sir[i]) k = phi[k];
        if (sir[k + 1] == sir[i]) k ++;
        phi[i] = k;
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
DoKmp ();
if (k != 0 && N % (N - k) == 0) L = N - k;
if (L == 0)
{
    printf ("1\n1\n");
    return 0;
}
if (L == 1)
{
    printf ("%d\n1\n", N);
    return 0;
}
for (int i=1; i<N; i++)
    ok[i] = (i % (i - phi[i]) != 0 || phi[i] == 0);
reverse (sir + 1, sir + N + 1), DoKmp ();
int cnt = 0;
for (int i=1; i<N; i++)
    ok[N - i] &= (i % (i - phi[i]) != 0 || phi[i] == 0), cnt += ok[N - i];
printf ("2\n%d\n", cnt);
return 0;
}


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

fn next_permutation(a: &mut Vec<usize>) -> bool {
  let N: usize = a.len();
  for i in (0..N-1).rev() {
    if a[i] < a[i + 1] {
      a[i + 1..].reverse();
      for j in i + 1..N {
        if a[i] < a[j] {
          a.swap(i, j);
          return true;
        }
      }
    }
  }
  false
}

fn main() {
  input! {
    N: usize,
    P: [Usize1; N],
    Q: [Usize1; N],
  }
  let mut v = vec![0; N];
  for i in 0..N {
    v[i] = i;
  }
  let mut a: i32 = -1;
  let mut b: i32 = -1;
  let mut cnt: i32 = 0;
  loop {
    if a == -1 && P == v {
      a = cnt;
    }
    if b == -1 && Q == v {
      b = cnt;
    }
    cnt += 1;
    if !next_permutation(&mut v) {
      break;
    }
  }
  println!("{}", i32::abs(a - b));
}

Measured memory_bytes: 2188
# ABC097b
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

x = int(input())

ans = 0
for b in range(1, x + 1):
    for p in range(2, math.floor(math.sqrt(x))+2):
        tmp = b ** p
        # print(tmp)
        if (tmp <= x):
            ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int A = scanner.nextInt();

        int modN = N%500;

        String ans = "No";
        if (modN<=A){
            ans = "Yes";
        }
        System.out.println(ans);
        scanner.close();
    }
}

Measured memory_bytes: 23636
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

ll dp[100005];
bool visited[100005];

struct Edge {
	int to, cost;
	bool operator<(const Edge &o) const {
		return cost > o.cost;
	}
};

int cal(ll x) {
	int ret = 0;
	while (x) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

int main() {
	int K; scanf("%d", &K);
	priority_queue<Edge> q;
	q.push({1, 0});
	while (!q.empty()) {
		Edge cur = q.top(); q.pop();
		if (visited[cur.to]) continue;
		visited[cur.to] = 1;
		if (cur.to == 0) 
			return !printf("%d", cur.cost + 1);
		q.push({(cur.to + 1) % K, cur.cost + 1});
		q.push({(cur.to * 10) % K, cur.cost});
	}
}

Measured memory_bytes: 1528
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int ageTaka = sc.nextInt();
      	int price = sc.nextInt();
      
		if(ageTaka >= 13) {
        	System.out.println(price);
        } else if(ageTaka <= 5) {
         	System.out.println(0); 
        } else {
         	System.out.println(price / 2); 
        }
    }
}

Measured memory_bytes: 21716
import sys

n, s = sys.stdin.read().split()
n = int(n)

def main():
    t = s
    t = t.replace('I', '+')
    t = t.replace('D', '-')
    x = 0
    res = 0
    for i in range(n):
        x += eval(t[i] + '1')
        res = max(res, x)

    return res

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

Measured memory_bytes: 3064
using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
        int[] i = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int A = i[0] == 1 ? 14 : i[0];
        int B = i[1] == 1 ? 14 : i[1];
        if(A < B)Console.WriteLine("Bob");
        else if(A > B)Console.WriteLine("Alice");
        else Console.WriteLine("Draw");
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

unsigned dp[100000][13] = {0};

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

  if (S[0] == '?')
    for (int ii=0; ii<10; ++ii) {
      dp[0][ii] = 1;
    }
  else
    dp[0][S[0]-'0'] = 1;
  
  for (int ii=1; ii<S.size(); ++ii) {
    for (int tens=0; tens<13; ++tens) {
      if (S[ii] == '?') {
	for (int ones=0; ones<10; ++ones) {
	  int residue = (tens*10+ones)%13;
	  dp[ii][residue] += dp[ii-1][tens];
	  dp[ii][residue] %= 1000000007;
	}
      } else {
	int ones = S[ii] - '0';
	int residue = (tens*10+ones)%13;
	dp[ii][residue] += dp[ii-1][tens];
	dp[ii][residue] %= 1000000007;
      }
    }
  }

  cout << dp[S.size()-1][5] << endl;

  return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl
#define REPEAT(i,n) for(int i=0;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 10000000000000


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

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

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

template<class T>
class Vec3
{
	public:
		T act[3];
};

int main(void) {


	int A,B;
	INPUT(A);
	INPUT(B);
	int ans = 0;
	
	REPEAT(i,20){
		int Kuchi = A*i-(i-1);
		if( Kuchi >= B ){
			ans = i;
			OUTPUT(ans);
			break;
		}
	}



	
		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> s;
	int cnt = 0;
	FOR(i, n) {
		if (s[i] == 'x') {
			cnt++;
			if (cnt == 2) {
				cout << i << endl;
				return 0;
			}
		}
		else cnt = 0;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3352
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

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

    N = N % K;
    if( abs(N-K) < N )
        N = abs(N-K);
    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

vector<int> E[100005];

int solve(int cur){
    int res=0,pl=1;
    vector<int> tmp;
    for(auto nxt :E[cur]){
        tmp.push_back(solve(nxt));
    }
    sort(tmp.begin(),tmp.end());
    for(int i=tmp.size()-1;i>=0;i--){
        res=max(res,tmp[i]+(pl));
        pl++;
    }
    return res;
}

int main(){
    int n; cin >> n;
    vector<int> a(n+1);
    for(int i=2;i<=n;i++){
        cin >> a[i];
        E[a[i]].push_back(i);
    }
    cout << solve(1) << endl;
}


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

typedef long long LL;
typedef unsigned long long ULL;

template<class T>
inline bool read(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(m) cout<<"nico "<<m<<endl
#define __m  int mid=l+(r-l)/2

const int maxn   = 1e5 + 7;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;

int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    //ios::sync_with_stdio(false);
    char now[500];
    cin>>now+1;
    int len=strlen(now+1);
    for(int i=1;i<=len-8;i++)
        cout<<now[i];
    cout<<endl;
    return 0;
}




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

using namespace std;
#define ll long long
int n,dem,res,k;
int a[200010];

int main()
{
    cin>>n>>k;
    int l=1;
    int r=1;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        r=max(r,a[i]);
    }
    ll mid;
    while (l!=r)
    {
        mid=(l+r)/2;
        ll s=0;
        for (int i=1; i<=n; i++)
            s+=(a[i]-1)/mid;
        if (s>k) l=mid+1; else r=mid;
    }
    cout<<l;
}


Measured memory_bytes: 4380
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define pb push_back
#define arrinp(v) for(auto &i:v) cin>>i;
#define arrout(v) for(auto &i:v) cout<<i<<" ";
#define newline cout<<endl;
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin >> t;
    while (t--) {
        int n;
        cin>>n;
        cout<<(!n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int ceil(int a,int b){
    if(a%b == 0)return a/b;
    else return a/b+1;
}

int pow(int a,int b){
    if(b == 0)return 1;
    int res = pow(a,b/2);
    res = res*res;
    if(b&1)res *= a;
    return res;
}

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){
 // }

     int a,b,c,d;
     cin >> a>> b >> c >> d;
     int x = ceil(c,b);
     int y = ceil(a,d);
     if(x <= y)cout  << "Yes" << endl;
     else cout << "No" << endl;
   
return 0;
	
	}




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

int main() {
    int x;
    cin >> x;
    const int m = 1000000;
    vector<int> a = {100, 101, 102, 103, 105};
    vector<int> dp(x + 1, -1);
    dp[0] = 0;
    for(int i = 0; i < 5; i++) {
        for(int j = 0; j <= x; j++) {
            if(dp[j] >= 0) {
                dp[j] = m;
            } else if(j < a[i] || dp[j - a[i]] <= 0) {
                dp[j] = -1;
            } else {
                dp[j] = dp[j - a[i]] - 1;
            }
        }
    }
    if(dp[x] >= 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    int ans = 0;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(all(L), greater<int>());
    rep(i, K) ans += L[i];
    cout << ans;
    cout << endl;
    return 0;
}



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

int main() {
    int k , s ;
    cin >> k >> s;
    int ans = 0 ;
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            if((s - (i + j))>= 0  && (s - (i + j)) <= k){
                ans++;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int r = 0;
		int t = 0;
		String str = "";
		//判定
		for(int i = 1; i <= 9; i++){
			t = n / i;
			r = n % i;
			 if(t <= 9 && r == 0){
				 str = "Yes";
				 break;
			 }
		}
		//出力文字決定
		if(str.isEmpty()){
			str = "No";
		}
		System.out.println(str);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define MAX_V int(2e5 + 1)
const ll mod = ll(1e9+7);

struct edge{int to, cost;};

vector<edge> G[MAX_V];
vector<bool> seen;
vector<ll> bunshi;
int N;

// O(log n)
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

//ax + by = gcd(a, b) �𖞂��� x, y ��Ԃ�
ll extgcd (ll a, ll b, ll& x, ll& y){
    ll d = a;
    if (b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a/b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

// O(log n)
// ax == 1 (mod m)�𖞂��� x
ll mod_inverse(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

int dfs(int v) {
    // �s�����������C���N�������g���Ȃ��烁��
    int res, tot = 0; // �c��[����������
    ll x = 0, y = mod_pow(2, N - 1, mod);
    ll sum = 1;
    seen[v] = true; // v ��K��ςɂ���
    for (auto e: G[v]){
        if (seen[e.to]) continue; 
        res = dfs(e.to);
        
        (y += mod - mod_pow(2, res, mod)) %= mod;
        
        tot += res;
    }
    res = N - 1 - tot;
    if (res > 0){
        (y += mod - mod_pow(2, res, mod)) %= mod;
    }
    (y += G[v].size() - 1) %= mod;

    bunshi[v] = y;
    if (G[v].size() <= 1){
        bunshi[v] = 0;
    }
    return tot + 1;
}
int main() {
    cin >> N;
    vector<int> A(N), B(N);
    
    rep(i, N - 1){
        cin >>  A[i] >> B[i];
        G[A[i] - 1].push_back((edge){B[i] - 1, 0});
        G[B[i] - 1].push_back((edge){A[i] - 1, 0});
    }
    
    seen.assign(N, false); // �S���_���u���K��v�ɏ�����
    bunshi.assign(N, 0); // �S���_��0�ɏ�����
    dfs(0);
    ll bunshi0 = 0;
    rep(i, N){
        (bunshi0 += bunshi[i]) %= mod;
    }
    ll bunbo = mod_pow(mod_inverse(2, mod), N, mod);
    ll ans = bunshi0 * bunbo % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 23552
n=int(input())
xy=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    xy.append(a)

if n==1:
    print(1)
    import sys
    sys.exit()
l=[]
ans=0
import itertools
for a,b in itertools.combinations(xy,2):
    p=(a[0]-b[0])
    q=(a[1]-b[1])
    if p!=0 or q!=0:
        l.append((p,q))
        l.append((-p,-q))

import collections
c=collections.Counter(l)
p=c.most_common()

for i in p:
   ans=max(ans,i[1])
print(n-ans)

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a == b)
        cout << "Draw" << endl;
    else if (a > b)
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;

    return 0;
}


Measured memory_bytes: 3604
n, Y = map(int, input().split())

y = Y / 1000

flag = 0

if 10 * n < y:
    print("-1 -1 -1")
elif y - n < 0:
    print("-1 -1 -1")
else:
    for a in range(0, n+1):
        for b in range(0, n-a+1):
            if 9*a + 4*b == y - n:
                print(a, b, n-a-b)
                flag = 1
                break
        if flag == 1:
            break
    if flag == 0:
        print("-1 -1 -1")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    ll ans=0;
    map<ll,ll> m;
    for (int i=0;i<N;++i){
        ans+=m[A[i]-i];
        ++m[-A[i]-i];
    }
    cout << ans << '\n';
}

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



ll k;
ll gcdtable[201][201];

ll gcd( ll a, ll b ){
	if ( a < b )
		return gcd( b, a );
	
	int k = a / b;
	if ( a - k * b == 0 )
		return b;
	return gcd( b, a - k * b );
}



int main(){
	cin >> k;
	
	for ( int i = 1; i <= k; i++ ){
		for ( int j = 1; j <= k; j++ ){
			gcdtable[i][j] = gcd( i, j );
		}
	}
	
	ll result = 0;
	for ( int a = 1; a <= k; a++ ){
		for ( int b = 0; b <= k; b++ ){
			ll ab = gcdtable[a][b];
			for ( int c = 0; c <= k; c++ ){
				result += gcdtable[ab][c];
			}
		}
	}
	
	cout << result << endl;
	
	return 0;
}




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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	int n; cin >> n;
	vector<ll> a(n);
	for(auto &e : a)cin >> e;
	int ans = -1;
	bool flag = true;
	do{	
		ans++;
		for(auto &e : a){
			if(e & 1){
				flag = false;
				break;
			}
			e >>= 1;
		}
	}while(flag);
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	lnt n,x,m;
	std::cin >> n >> x >> m;
	V<lnt> to(m,-1);
	lnt cur=x;
	lnt ans=x;
	std::map<lnt,lnt> map;
	rep(i,n) {
		map[cur]=i;
		if(i==n-1) {
			print(ans);
			return 0;
		}
		to[cur]=cur*cur%m;
		cur=to[cur];
		if(to[cur]!=-1) {
			lnt cy=i-map[cur]+1;
			lnt left=n-1-i;
			lnt csum=0;
			lnt xx=cur;
			rep(j,cy) {
				csum+=xx;
				xx=to[xx];
			}
			ans+=(left/cy)*csum;
			left%=cy;
			xx=cur;
			rep(j,left) {
				ans+=xx;
				xx=to[xx];
			}
			print(ans);
			return 0;
		} else {
			ans+=cur;
		}
	}
}


Measured memory_bytes: 7128
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

/*
  計算量はたかだか2^9
*/
int ans;
void solve(int now,int val,int base,int *a,int *b,int borrow,int k){
  if (k < 0)return;
  if (now == -1){
    ans = max(ans,val);
    return;
  }
  if (a[now]-borrow >= b[now]){
    solve(now-1,val + base * (a[now]-borrow-b[now]   ),base*10,a,b,0,k);
  }else {
    solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,1,k);
    solve(now-1,val + base * (a[now]-borrow+10-b[now]),base*10,a,b,0,k-1);
  }
}

main(){
  int a,b,k;
  char buf[20];
  int aa[12],ba[12];
  while(cin>>a>>b>>k){
    sprintf(buf,"%d",a);
    int len = strlen(buf);
    rep(i,len)aa[i] = buf[i]-'0';
    sprintf(buf,"%d",b);
    int lenb = strlen(buf);
    rep(i,lenb)ba[i+len-lenb] = buf[i] - '0';
    rep(i,len-lenb)ba[i] = 0;
    ans = 0;
    solve(len-1,0,1,aa,ba,0,k);    
    cout << ans << endl;
  }
  return 0;
}

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

void printdeq(deque<string> &deq){
    for(auto itr=deq.begin(); itr!=deq.end(); itr++){
        cout << *itr;
    }
}

void rprintdeq(deque<string> &deq){
    for(auto itr=deq.end()-1; itr!=deq.begin()-1; itr--){
        cout << *itr;
    }
}

void solve(){
    string S;
    int q;
    cin >> S;
    cin >> q;
    int num, f;
    deque<string> right, left;
    string c;
    int flag = 0; //0なら反転しない、1なら反転する
    for(int i=0; i<q; i++){
        cin >> num;
        if(num == 1){
            if(flag == 0) flag = 1;
            else flag = 0;
        }
        if(num == 2){
            cin >> f >> c;
            if(f == 1){
                if(flag == 0) left.push_front(c);
                else right.push_back(c);
            }else{
                if(flag == 0) right.push_back(c);
                else left.push_front(c);
            }
        }         
    }

    if(flag == 0){
        printdeq(left);
        cout << S;
        printdeq(right);
        cout << endl;
    }else{
        reverse(S.begin(), S.end());
        rprintdeq(right);
        cout << S;
        rprintdeq(left);
        cout << endl;
    }  

}

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

Measured memory_bytes: 11728
#include <cstdio>
#include <vector>
using namespace std;

#define MIN(a,b) ((a)<(b)?(a):(b))

void merge(vector<pair<int,int> >& w, int left, int mid, int right) {
	vector<pair<int,int> > L,R;
	int n1=mid-left;
	int n2=right-mid;
	int i=0,j=0,k;
	L.resize(n1+1);
	R.resize(n2+1);
	for(i=0; i<n1; ++i) {
		L[i]=w[left+i];
	}
	L[n1].first = -1;
	L[n1].second = 1000000001;
	for(i=0; i<n2; ++i) {
		R[i]=w[mid+i];
	}
	R[n2].first = -1;
	R[n2].second = 1000000001;

	i=j=0;
	for(k=left; k<right; ++k) {
		if(L[i].second < R[j].second) {
			w[k]=L[i];
			++i;
		} else {
			w[k]=R[j];
			++j;
		}
	}
	return;
}

void mergeSort(vector<pair<int,int> >& w, int left, int right) {
	if(left+1<right) {
		int mid=left+(right-left)/2;
		mergeSort(w,left,mid);
		mergeSort(w,mid,right);
		merge(w,left,mid,right);
	}
	return;
}

int main() {
	int n;
	int i,j;
	int total=0;
	int subtotal,c;
	vector<int> checker;
	vector<pair<int,int> > w; // first=original_index, second =weight_value will be sorted.
	scanf("%d",&n);
	w.resize(n);
	checker.resize(n);
	for(i=0; i<n; ++i) {
		checker[i]=0;
		w[i].first=i;
		scanf("%d",&w[i].second);
	}
	mergeSort(w,0,n);
	for(i=0; i<n; ++i) {
		if(checker[i]==1 || w[i].first==i) {
			continue; // already checked or unmoved
		}
		c=subtotal=0;
		checker[i]=1;
		j=w[i].first;
		while(j!=i) {
			subtotal+=w[i].second+w[j].second;
			checker[j]=1;
			j=w[j].first;
			++c;
		}
		total+=MIN(subtotal,subtotal-w[j].second*(c-2)+w[0].second*(c+2));
	}
	printf("%d\n",total);
	return 0;
}

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

int main() {
	long long x, y;
	cin >> x >> y;
	if (abs(x - y) <= 1){
		cout << "Brown" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
	
}

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

int main() {
    int x,y;
    cin >> x >> y;
    bool isExist = false;
    for(int i=0; i<=x; i++){
        if(2*i + 4*(x-i) == y){
            isExist = true;
            break;
        }
    }
    if(isExist) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N;
	cin >> N;
	int i = 2;
	cout << N << ':';
	while (i <= sqrt(N)) {
		if (N % i == 0) {
			cout << ' ' << i;
			N /= i;
		}
		else {
			++i;
		}
	}
	if (N != 1) cout << ' ' << N;
	cout << endl;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
using ll = long long;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

struct unionfindtree {
    vector<int> par,rank;
    unionfindtree(int n):par(n),rank(n,0) {
        rep(i,n) par[i] = i;
    }
    int root(int n) {
        if(par[n] == n) return n;
        else return par[n] = root(par[n]);
    }
    bool same(int i,int j) {
        return root(i) == root(j);
    }
    void unite(int i,int j) {
        int ri = root(i);
        int rj = root(j);
        if(ri == rj) return;

        if(rank[ri] < rank[rj]) {
            par[ri] = rj;
        } else {
            par[rj] = ri;
            if(rank[ri] == rank[rj]) rank[ri]++;
        }
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    unionfindtree u(n);
    vector<int> p(n);
    map<int,int> ma;
    rep(i,n) cin >> p[i];
    rep(i,n) p[i]--;
    rep(i,n) ma[p[i]] = i;
    rep(i,m) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        u.unite(x,y);
    }
    int ans = 0;
    rep(i,n) if(u.same(i,ma[i]) || p[i] == i) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int deg[100005];
vector<int> block[100005];

int main() {
  // union-find、同じグループからブロックの人数を引く
  // 違うグループのブロックは無視
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N+1);  // 1-indexed
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    uf.unite(A, B);
    deg[A]++;
    deg[B]++;
  }
  rep(i, K) {
    int C, D;
    cin >> C >> D;
    if (uf.same(C, D)) {
      block[C].push_back(D);
      block[D].push_back(C);
    }
  }
  for (int i = 1; i <= N; i++) {
    int ans = uf.size(i) - deg[i] - sz(block[i]) - 1;
    cout << ans << ' ';
  }
  return 0;
}

Measured memory_bytes: 9148
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

void swap(int& X, int& Y) {
    int tmp = X;
    X = Y;
    Y = tmp;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int X, Y, Z;
    cin >> X >> Y >> Z;
    swap(X, Y);
    swap(X, Z);

    cout << X  << " "  << Y << " " << Z << endl;
    return 0;
}

Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}


int main() {
    ll N, D;
    cin >> N >> D;
    ll ans = 0;
    ll now = 0;
    while(now < N) {
        now += 1 + 2 * D;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
// inline int read() {
// 	int q=0,w=1;char c=getchar();
// 	while(!isdigit(c)){if(c=='-')w=-1;c=getchar()}
// 	while(isdigit(c))q=q*10+c-'0',c=getchar();
// 	return w*q;
// }
int D, T, S;
int main() {
	cin >> D >> T >> S;
	puts(T * S >= D ? "Yes" : "No"); 
	return 0;
}

Measured memory_bytes: 3620