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

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;

vector<pair<ll, ll> > factorize(ll x){
	vector<pair<ll, ll> > vv;
	for(ll i = 2; i * i <= x; i++){
		if(x % i == 0){
			ll cnt = 0;
			while(x % i == 0){
				x /= i;
				cnt++;
			}
			vv.push_back(make_pair(i, cnt));
		}
	}
	
	if(x > 1){
		vv.push_back(make_pair(x, 1));
	}

	return vv;
}

ll quickPow(ll x, ll y){
	if(y == 0){
		return 1;
	}

	ll tmp = quickPow(x, y / 2);
	if(y % 2){
		return (((tmp * tmp) % MOD) * (x % MOD)) % MOD;
	}

	return (tmp * tmp) % MOD;
}

ll fact[maxN], inv[maxN];

void preCal(){
	fact[0] = 1;
	for(int i = 1; i < maxN; i++){
		fact[i] = (fact[i - 1] * i) % MOD;
	}

	for(int i = 0; i < maxN; i++){
		inv[i] = quickPow(fact[i], MOD - 2);
	}
}

ll nCk(ll N, ll K){
	ll ans = fact[N];
	ans = (ans * inv[K]) % MOD;
	ans = (ans * inv[N - K]) % MOD;

	return ans;
}

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

	ll n, m;	cin >> n >> m;

	vector<pair<ll, ll> > divi = factorize(m);
	
	ll fRes = 1;

	for(int i = 0, L = (int)divi.size(); i < L; i++){
		ll a = divi[i].second;
		//cerr << a + n - 1 << ' ' << n - 1 << ' ' << nCk(a + n - 1, n - 1) << '\n';
		fRes = (fRes * nCk(a + n - 1, n - 1)) % MOD;	
	}

	cout << fRes << '\n';

	return 0;
}

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

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(){
    ll x; cin >> x;
    int year = 0;
    ll depo = 100;
    while (depo < x){
        depo += 0.01 * depo;
        year += 1;
    }
    //cout << depo << endl;
    cout << year << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String tmp1;
		int tmp2,i=0,j=0;
		int s[] = new int[13];
		int h[] = new int[13];
		int c[] = new int[13];
		int d[] = new int[13];
		while(i<n) {
			tmp1 = scan.next();
			tmp2 = scan.nextInt();
			if(tmp1.equals("S")) s[tmp2-1] = tmp2;
			if(tmp1.equals("H")) h[tmp2-1] = tmp2;
			if(tmp1.equals("C")) c[tmp2-1] = tmp2;
			if(tmp1.equals("D")) d[tmp2-1] = tmp2;
			i++;
		}

		for(j=0;j<13;j++) {
			if(s[j] == 0) System.out.println("S "+(j+1));
		}

		for(j=0;j<13;j++) {
			if(h[j] == 0) System.out.println("H "+(j+1));
		}
		
		for(j=0;j<13;j++) {
			if(c[j] == 0) System.out.println("C "+(j+1));
		}
		
		for(j=0;j<13;j++) {
			if(d[j] == 0) System.out.println("D "+(j+1));
		}
		scan.close();
	}
}



Measured memory_bytes: 26392
import java.util.Scanner;

//20180508
//01

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

		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		int count = 0;

		for(int i = a;i <= b;i++) {
			if((c % i) == 0) {
				count++;
			}
		}

		System.out.println(count);

    	scanner.close();
    }
}



Measured memory_bytes: 26384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  int t,j,k,l,p,n,i,x;
   
   cin>>n>>k;
   long int a[n];
   for(i=0;i<n;i++)
   cin>>a[i];
   sort(a,a+n);
   l=0;
   
   for(i=0;i<k;i++)
   l=l+a[i];
   cout<<l<<endl;
   
    
    
    
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
using namespace std;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

char s[2003];
int pres[2003][2003], preh[2003][2003];
int q(int x, int y) {
    return preh[x][y] - preh[x][y - 1];
}

int main() {
    int n = read(), m = read();
    for (int i = 1; i <= n; ++i) {
        scanf("%s", s + 1);
        for (int j = 1; j <= m; ++j) {
            if (s[j] == '#') {
                pres[m + i - j][i + j]++;
                preh[m + i - j][i + j]++;
            }
        }
    }
    for (int j = 2; j <= m + n; ++j) {
        for (int i = 1; i <= m + n - 1; ++i) {
            pres[i][j] += pres[i - 1][j];
            preh[i][j] += preh[i][j - 1];
        }
    }
    long long res = 0;
    for (int k = 2; k <= m + n - 1; k ++) {
        for (int i = 1; i + k - 1 <= m + n - 1; ++i) {
            for (int j = 2; j + k - 1 <= m + n; ++j) {
                int sum = 0;
                if (q(i, j) && q(i + k - 1, j)) {
                    res += pres[i + k - 1][j + k - 1] - pres[i - 1][j + k - 1];
                    sum++;
                }
                if (q(i, j + k - 1) && q(i, j)) {
                    res += preh[i + k - 1][j + k - 1] - preh[i + k - 1][j - 1];
                    sum++;
                }
                if (q(i + k - 1, j) && q(i + k - 1, j + k - 1)) {
                    res += preh[i][j + k - 1] - preh[i][j - 1];
                    sum++;
                }
                if (q(i + k - 1, j + k - 1) && q(i, j + k - 1)) {
                    res += pres[i + k - 1][j] - pres[i - 1][j];
                    sum++;
                }
                if (sum == 2) res -= 1;
                if (sum == 4) res -= 4;
            }
        }
    }
    printf("%lld\n", res);
    return 0;
}

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

int main() {
  int N, answer=0;
  cin >> N;
  vector<int> d(N);
  for (int i=0; i<N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  if (d.at(N/2-1) != d.at(N/2)) {
    answer = d.at(N/2)-d.at(N/2-1);
  }
  cout << answer << endl;
}

Measured memory_bytes: 640
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});

var args = [];

reader.on('line', function (input) {
  args.push(input);
});


reader.on('close', function () {
    var str = args[0].split(" ");
    console.log("A" + str[1].substr(0, 1) + "C");
});


Measured memory_bytes: 20852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  int Matrix[H+1][W+1];
  for (int i = 0; i <= H; i++) {
    for (int j = 0; j <= W; j++) {
      Matrix[i][j] = 1;
    }
  }
  if (h == 1 && w == 1) {
    cout << "No" << endl;
    return 0;
  } else if (h == 1) {
    int tmp[W+1];
    for (int i = 1; i <= W; i++) {
      if (i % w == 1) {
        tmp[i] = 100000000 - w + 1;
      } else if (i % w == 0) {
        tmp[i] = -100000000;
      } else {
        tmp[i] = 1;
      }
    }
    ll s = 0;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        Matrix[i][j] = tmp[j];
        s += Matrix[i][j];
      }
    }
    if (s > 0) {
      cout << "Yes" << endl;
      for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
          cout << Matrix[i][j] << " ";
        }
        cout << endl;
      }
    } else  {
      cout << "No" << endl;
    }
    return 0;
  } else if (w == 1) {
    int tmp[H+1];
    for (int i = 1; i <= H; i++) {
      if (i % h == 1) {
        tmp[i] = 100000000 - h + 1;
      } else if (i % h == 0) {
        tmp[i] = -100000000;
      } else {
        tmp[i] = 1;
      }
    }
    ll t = 0;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        Matrix[i][j] = tmp[i];
        t += Matrix[i][j];
      }
    }
    if (t > 0) {
      cout << "Yes" << endl;
      for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
          cout << Matrix[i][j] << " ";
        }
        cout << endl;
      }
    } else {
      cout << "No" << endl;
    }
    return 0;
  }
  ll sum = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (i % h == 0 && j % w == 0) {
        Matrix[i][j] = -100000000;
      } else if (i % h == 1 && j % w == 1) {
        Matrix[i][j] = 100000000 - (h*w) + 1;
      } else {
        Matrix[i][j] = 1;
      }
      sum += Matrix[i][j];
    }
  }
  if (sum > 0) {
    cout << "Yes" << endl;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cout << Matrix[i][j] << " ";
      }
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const ll MOD = TEN(9) + 7;
ll n, k;

int main() {
    fastio();

    cin >> n >> k;

    ll ans = 0;
    for (ll i = k; i <= n + 1; i++) {
        ll a = i * (i - 1) / 2 % MOD;
        ll b = i * (n - i + 1 + n) / 2 % MOD;
        ans = (ans + b - a + 1 + MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

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

		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();

		int w1 = tx - sx;
		int h1 = ty - sy;
		int w2 = w1 + 1;
		int h2 = h1 + 1;

		char u = 'U';
		char d = 'D';
		char l = 'L';
		char r = 'R';

		char[] c = {u, r, d, l, l, u, r, d, r, d, l, u};
		int[] dis = {h1, w1, h1, w1, 1, h2, w2, 1, 1, h2, w2, 1};

		int sumDis = w1 * 2 + h1 * 2 + w2 * 2 + h2 * 2 + 4;

		StringBuilder ans = new StringBuilder(sumDis);

		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < dis[i]; j++) {
				ans.append(c[i]);
			}
		}

		System.out.println(ans.toString());
		sc.close();
	}

}


Measured memory_bytes: 25172
// AOJ 0647 Stove
// 2018.3.28 bal4u

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int dt[100002];

int cmp(int *a, int *b) { return *b - *a; }

int main()
{
	int n, k, i, t0, t1, t2, s;

	n = in(), k = in();
	if (k >= n) { printf("%d\n", n); return 0; }

	n--, t0 = t1 = in();
	for (i = 0; i < n; i++)  t2 = in(), dt[i] = t2-t1-1, t1 = t2;
	if (k == 1) { printf("%d\n", t2-t0+1); return 0; }

	qsort(dt, n, sizeof(int), cmp);

	s = 0, k--;
	for (i = 0; k--; i++) s += dt[i];
	printf("%d\n", t2-t0+1-s);
	return 0;
}


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

const ll INF = 1LL << 40;
int N;
ll xs, ys, xt, yt;
ll x[1010], y[1010], r[1010];
double dis[1010][1010];

double calcDis(int s, int t) {
  double d = hypot(x[s]-x[t], y[s]-y[t]);
  return max(0.0, d - r[s] - r[t]);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> xs >> ys >> xt >> yt >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> r[i];
  }
  x[N] = xs; y[N] = ys; r[N] = 0;
  x[N+1] = xt; y[N+1] = yt; r[N+1] = 0;
  
  fill_n((double*)dis, 1010*1010, INF);
  for (int i = 0; i < N+2; i++) {
    for (int j = 0; j < N+2; j++) {
      dis[i][j] = calcDis(i, j);
    }
  }
  for (int k = 0; k < N+2; k++) {
    for (int i = 0; i < N+2; i++) {
      for (int j = 0; j < N+2; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
      }
    }
  }
  cout << dis[N][N+1] << endl;

  return 0;
}

Measured memory_bytes: 8320
#include<iostream>                                        
using namespace  std;                                     
                                                          
int main(){                                               
  int m,f,r;                                              
  char grade;                                             
  while(1){                                               
    cin >> m >> f >> r;                                   
    if(m == -1 && f == -1 && r == -1) break;              
    int sum = m + f;                                      
    if(m == -1 || f == -1)                                
      grade = 'F';                                        
    else if(sum >= 80)                                    
      grade = 'A';                                        
    else if(sum >= 65 && sum < 80)                        
      grade = 'B';                                        
    else if(sum >= 50 && sum < 65)                        
      grade = 'C';                                        
    else if(sum >= 30 && sum < 50){                       
      if(r >= 50)                                         
        grade = 'C';                                      
      else                                                
        grade = 'D';                                      
    }                                                     
    else if(sum <= 30)                                    
      grade = 'F';                                        
    cout << grade << endl;                                
  }                                                       
                                                          
  return 0;                                               
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

signed _main() {
  // 頂点数と辺数
  int N; cin >> N;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  for (int i = 0; i < N; ++i) {
    int u,k; cin >> u >> k;
    u--;
    rep(j,k){
      int v; cin >> v;
      v--;
      G[u].push_back(v);
    }
  }

  // BFS のためのデータ構造
  vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
  queue<int> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0] = 0;
  que.push(0); // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : G[v]) {
      if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }

  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  for (int v = 0; v < N; ++v) cout << v+1 << " " << dist[v] << endl;
}



Measured memory_bytes: 3240
/*Kadai3_2
  saitomo*/

#include<stdio.h>

int main(void){
  int num,first_num;
  scanf("%d",&num);
  first_num = num%10;//1の位を求める
  if(first_num==3){//問題文の通りに条件分岐
    printf("bon\n");
  }else if(first_num==0 || first_num==1 || first_num==6 || first_num==8){
    printf("pon\n");
  }else{
    printf("hon\n");
  }
  return 0;
}


Measured memory_bytes: 1616
#include <iostream>
int main() {
    long long int a, b, c, d, res[5];
    std:: cin >> a >> b >> c >> d;
    res[0] = a*c;
    res[1] = a*d;
    res[2] = b*c;
    res[3] = b*d;
    for(int i=1; i<4; i++) {
        if (res[i]>res[0]) {
            res[0] = res[i];
        }
    }
    std:: cout << res[0] << std:: endl;
    return 0;
}

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

vector<map<int, int> >dp(1000000);
int arr[1000000];
int inf = 1e16;

int solve(int i, int k){
    if(i<0 && k==0)return 0;
    if(i<0)return -inf;
    int aa = (i+1+1)/2;
    if(k > aa)return -inf;
    if(dp[i].find(k) != dp[i].end())return dp[i][k];
    int alpha = max(solve(i-1, k), arr[i]+solve(i-2,k-1));
    return dp[i][k] = alpha;
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)cin>>arr[i];
    cout<<solve(n-1, n/2);
    return 0;
}

Measured memory_bytes: 79752
#include <bits/stdc++.h>
#define int long long
using namespace std;
int x;
int a,b,ans;
int m[222][222];
signed main(){
    cin>>a>>b;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>m[i][j];
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                m[i][j]=min(m[i][j],m[i][k]+m[k][j]);
            }
        }
    }
    for(int i=0;i<a*b;i++){
        cin>>x;
        if(x==-1)continue;
        ans+=m[x][1];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x,y,z,a;
     cin >> x;
    y=x/3600;
    z=(x%3600)/60;
    a=(x%3600)%60;
   cout << y << ":" << z << ":" << a << endl; 
   return 0;
}


Measured memory_bytes: 3096
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	long long int a[n]={};
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	int ans=1;
	int u=0;
	for(int i=0;i<n-1;i++){
		if(a[i+1]==a[i]){
			if(i==u)u++;
			continue;
		}
		if((a[i+1]>a[i])!=(a[u+1]>a[u])){
			ans++;
			u=i+1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,i,mx=0,p=0;
    cin>>a>>b;
    mx=max(a,b);
    for(i=1; i<a*b; i++)
    {
        p=mx*i;
        if(p%a==0 && p%b==0)
        {
            cout<<p<<endl;
            break;

        }

    }


}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		do {
			String circleStr = br.readLine();
			String answer = br.readLine();
			int circleLen = circleStr.length();
			int answerLen = answer.length();
			String result = "No";
			for (int i = 0; i < circleLen; i++) {
				char c = circleStr.charAt(i);
				int cIndex = i;
				for (int j = 0; j < answerLen; j++) {
					if (c == answer.charAt(j)) {
						if (answerLen - 1 == j) {
							result = "Yes";
							break;
						}
						if (circleLen - 1 == cIndex) {
							cIndex = 0;
						} else {
							cIndex++;
						}
						c = circleStr.charAt(cIndex);
					} else {
						break;
				}
					}
				if (result.equals("Yes")) break;
			}
			System.out.println(result);
		} while (br.ready());
	}	
}

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

int main(){
  int l, r, d;  cin >> l >> r >> d;
  int ans = 0;
  for(int i=l; i<=r; i++)
    if(i % d == 0)
      ans++;

  cout << ans << endl;

  return 0;
}


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

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    rep(i,x) r.push_back(p[i]);
    rep(i,y) r.push_back(q[i]);

    sort(r.rbegin(),r.rend());
    ll ans = 0;
    rep(i,x+y) ans += r[i];
    cout << ans << endl;
    return 0;

}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/08/25  Problem: ARC 999 A / Link: http://arc999.contest.atcoder.jp/tasks/arc999_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

	int N, K; cin >> N >> K;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
		if (a[i] == 0)K--;
	}
	a.push_back(0);
	SORT(a);
	UNIQ(a);
	int cent = lower_bound(ALL(a), 0) - a.begin();
	LL ans = LINF;
	VL L(N + 2, LINF);
	L[0] = 0;
	FOR(i, 0, cent) {
		L[i + 1] = abs(a[cent-i-1]);
	}

	VL R(N + 2, LINF);
	R[0] = 0;
	FOR(i, cent + 1, SZ(a)) {
		R[i - cent] = a[i];
	}
	FOR(i, 0,K+1) {// 左にi個
		LL Ls = L[i];
		LL Rs = R[K - i];
		ans = min({ ans, Ls * 2 + Rs, 2 * Rs + Ls });
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2672
B=[]

while 1:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    A.sort()
    max=0
    for i in range(n):
        if A[i]>m:
            break
        for j in range(i+1,n):
            sum=A[i]+A[j]
            if sum>m:
                break
            elif sum>max:
                max=sum

    if max==0:
        B.append("NONE")
    else:
        B.append(max)

for b in B:
    print(b)



Measured memory_bytes: 5720
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second     
#define fio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define mp make_pair
#define int long long
using namespace std;
const int INF = 1e9;
const int MAX = 1e5+3;
int MOD = 1e9+7;
int n, M;
vector<int> adj[MAX];
vector<int> ways;
vector<int> ways_up;
vector<int> pre[MAX];
vector<int> tree[MAX];
vector<int> ans;

void build(int s, int node, int l, int r)
{
   if(l > r)
      return ;

   if(l == r)
   {
      tree[s][node] = pre[s][l]+1;
      return;
   }

   int mid = (l+r)/2;
   build(s, 2*node, l, mid);
   build(s, 2*node+1, mid+1, r);
   tree[s][node] = (tree[s][2*node]*tree[s][2*node+1])%M;
}


void build_util(int s)
{
   int sz = pre[s].size();
   if(!sz) return ;
   tree[s].resize(4*sz, 1);
   build(s, 1, 0, sz-1);
}

int query(int s, int node, int st, int en, int l, int r)
{
   if(l > r)
      return 1;

   if(st > r || en < l)
      return 1;

   if(st >= l && en <= r)
      return tree[s][node];

   int mid = (st+en)/2;
   int p1 = query(s, 2*node, st, mid, l, r);
   int p2 = query(s, 2*node+1, mid+1, en, l, r);
   return (p1*p2)%M;
}


void dfs(int s, int par)
{
   for(int i=0;i<adj[s].size();i++)
   {
      if(adj[s][i] != par)
      {
         dfs(adj[s][i], s);
         ways[s] = (ways[s]*(ways[adj[s][i]]+1))%M;
         pre[s].pb(ways[adj[s][i]]);
      }
   }
   build_util(s);
}

int cal_fun(int s, int par)
{
   bool is_par_done = false;
   for(int i=0;i<adj[s].size();i++)
   {
      if(adj[s][i] == par){ is_par_done = true; continue; }
      ans[s] = (ans[s]*(ways[adj[s][i]]+1))%M;
      int l1, r1, l2, r2;
      if(!is_par_done)
         l1 = 0, r1 = i-1, l2=i+1, r2 = (int)pre[s].size()-1;
      else l1 = 0, r1 = i-2, l2 = i, r2 = (int)pre[s].size()-1;
      ans[adj[s][i]] = (ways_up[s]+1)*((query(s, 1,  0, (int)pre[s].size()-1, l1, r1)*query(s,1, 0, (int)pre[s].size()-1, l2, r2))%M)%M+1;
      ways_up[adj[s][i]] = ans[adj[s][i]]-1;
      cal_fun(adj[s][i], s);
   }

}




int32_t main()
{
   cin>>n>>M;
   ways.resize(n+2, 1);
   ways_up.resize(n+2, 0);
   ans.resize(n+2, 1);
   for(int i=0;i<n-1;i++)
   {
      int x, y;
      cin>>x>>y;
      adj[x].pb(y);
      adj[y].pb(x);
   }
   dfs(1, -1);
   cal_fun(1, -1);
   for(int i=1;i<=n;i++)
      cout<<ans[i]%M<<"\n";


}

Measured memory_bytes: 31232
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int64
	fmt.Scan(&n)
	m := int64(math.Sqrt(float64(n)))
	if m * m == n {
		fmt.Println(2 * m - 2)
	} else {
		for i := m; i >= 1; i-- {
			if n % i == 0 {
				fmt.Println(n / i + i - 2)
				break
			}
		}
	}
}

Measured memory_bytes: 512
#include<cstdio>

using namespace std;

int pow(int x, int n){
	if(n == 0) return 1;
	return x * pow(x, n - 1);
}

int main(){
	int n, k; scanf("%d %d", &n, &k);
	printf("%d\n", k * pow(k - 1, n - 1));
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	rep(i, n) {
		vector<int> a(26), b(26);
		for (int j = 0; j < i; j ++) a[s[j] - 'a'] ++;
		for (int j = i; j < n; j ++) b[s[j] - 'a'] ++;
		int cnt = 0;
		for (int j = 0; j < 26; j ++) cnt += a[j] > 0 && b[j] > 0;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
        return 0;
}


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

using namespace std;

typedef long long ll;
  
int main(){
  int a, b;
  cin >> a >> b;
  if(1<=a && a<=9 && 1<=b && b<=9){
    printf("%d\n", a*b);
  }
  else printf("-1\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v)
  { for (auto & x : v) is >> x; return is; }

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    {os << (i > 0 ? "," : "") << v[i];}
  return os << "}";
}

template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (T&& t) noexcept
      : T(std::forward<T>(t)) {}
    template<typename... Args>
    constexpr decltype(auto) operator()(Args&&... args) const
      {return T::operator()(*this, std::forward<Args>(args)...);}
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{std::forward<T>(t)};
}

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  while (true) {
    int n; std::cin >> n;
    if (n == 0) exit(0);
    std::vector<int> w(n); std::cin >> w;
    auto dp  = make_vector<2, int>(n + 1, n + 1, -1);
    auto ckd = make_vector<2, int>(n + 1, n + 1, false);
    auto ret = n - fix([&](auto f, int l, int r) -> int {
      if (at(ckd, l, r)) return at(dp, l, r);
      if (l == r) return 0;
      auto& ret = at(dp, l, r);
      ret = f(l + 1, r) + 1;
      rep(i, l + 1, r) {
        if (std::abs(w.at(l) - w.at(i)) <= 1 && f(l + 1, i) == 0) {
          cmn(ret, f(i + 1, r));
        }
      }
      at(ckd, l, r) = true;
      return ret;
    })(0, n);
    std::cout << ret << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
vector<ll> v[100005];
ll marked[100005];
void dfs(ll idx)
{
	marked[idx] = 1;
	ll i;
	ll sz = v[idx].size();
	ll y;
	F(y,0,sz)
	{
		ll x = v[idx][y];
		if(marked[x]==0)
		{
			dfs(x);
		}
	}
	
}
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		ll n;
		ll m;
		cin >> n >> m;
		ll i;
		F(i,0,m)
		{
			ll a,b,c;
			cin >> a >> b >> c;
			v[a].p_b(b);
			v[b].p_b(a);
			
		}
			
		ll ans  = 0;
		F(i,1,n+1)
		{
			if(marked[i] == 0)
			{
				ans++;
				dfs(i);
			}
		}
		cout << ans << endl;
		
	}
	return 0;

}



Measured memory_bytes: 9600
# This was written by chizuchizu
import sys
# import collections

# import bisect
# import math
import numpy as np

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()

    """この下から書いてね"""
    # n, m = ip.IL()
    # a = np.array(ip.IL())
    # for _ in range(m):
    #     a[np.argmax(a)] //= 2
    # print(np.sum(a))
    n = int(input())
    s = ip.SLS(n)
    print(len(set(s)))


main()


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

int main() {
    int A, B;

    cin >> A >> B;

    if (-1 < A && A < 6){
            cout << 0 << endl;
    }

    if (5 < A && A < 13){
            cout << B/2 << endl;
    }

    if (12 < A){
            cout << B << endl;
    }

    return 0;

}


Measured memory_bytes: 256
S = input()
S = S[::-1]
while len(S) != 0:
  num = len(S)
  if S.find('maerd') == 0:
    S = S.replace('maerd', '', 1)
  if S.find('remaerd') == 0:
    S = S.replace('remaerd', '', 1)
  if S.find('esare') == 0:
    S = S.replace('esare', '', 1)
  if S.find('resare') == 0:
    S = S.replace('resare', '', 1)
  if num == len(S):
    print('NO')
    exit(0)
print('YES')


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#define N 2505
#define M 5005
#define F first
#define S second
using namespace std;
typedef long long ll;

ll n, m, p, a[M], b[M], c[M], d[N];
int main() {
	int i, j;
	cin >> n >> m >> p;
	for(i=0; i<m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--, b[i]--;
		c[i] -= p;
	}
	for(i=1; i<n; i++) d[i] = -1e18;
	for(i=0; i<2*n; i++) for(j=0; j<m; j++) {
		if(d[a[j]] == -1e18) continue;
		if(d[a[j]] + c[j] > d[b[j]]) {
			if(i<n-1) d[b[j]] = d[a[j]] + c[j];
			else d[b[j]] = 1e18;
		}
	}
	if(d[n-1]==1e18) cout << -1;
	else cout << max(0LL, d[n-1]);
	return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(b, a);
    while (a) {
        vvi data(a, vi(b));
        rep(i, a) {
            rep(j, b) {
                cin >> data[i][j];
            }
        }
        
       // cout << "=======" << endl;
        vvi dp(a+1, vi(b, 0));
        rep(i, b) {
            if (!data[0][i]) {
                dp[0][i] = 1;
            }
        }
        

        rep(i, a-1) {
            rep(j, b) {
                if (!data[i][j]) {
                    for (int k = -1; k < 2; k++) {
                        if (data[i+1][j+k] == 2) {
                            if (!k) {
                                dp[i+1][j] += dp[i][j];
                            }
                        } else if (!data[i+1][j+k]) {
                            dp[i+1][j+k] += dp[i][j];
                        }
                    }
                } else if (data[i][j] == 2) {
                    dp[i+2][j] += dp[i][j];
                }
            }
        }
/*
        rep(i, a+1) {
            rep(j, b) {
                cout << dp[i][j] << " ";
            }cout << endl;
        }*/

        int ans = 0;
        rep(i, b) {
            if (data[a-1][i] != 1) {
                ans += dp[a][i] + dp[a-1][i];
            } else {
                ans += dp[a][i];
            }
            /*
            if (data[a-1][i] == 1) {
                //cout << dp[a][i] << " ";
                ans += dp[a][i];
            } else {
                //cout << dp[a-1][i] << " ";
                ans += dp[a-1][i];
            }
            */
        }
        cout << ans << endl;
        cin >> b >> a;
    }

    return 0;
}

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

int i;

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

    if (S.substr(2, 1) == S.substr(3, 1) &&
        S.substr(4, 1) == S.substr(5, 1))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll a,b; cin>>a>>b;
	a = ebob(a,b);
	ll res = 1;
	if(a == 1){
		cout<<1;
		return 0;
	}else if(a == 2 || a == 3){
		cout<<2;
		return 0;
	}
	ll temp = 1;
	for(ll i = 2; i*i <= a; i++){
		if(temp < a && (a/temp) % i == 0){
			res++;
			while(temp < a){
				temp *= i;
				if(a % temp){
					temp /= i;
					break;
				}
			}
		}
	}
	if(a > temp) res++;
	cout<<res;
	return 0;
}

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

namespace AGC011
{
    class B
    {
        static void Main(string[] args)
        {

            long N = int.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            A = A.OrderBy(x => x).ToArray();

            long[] S = new long[N + 1];
            for (int i = 1; i < N + 1; i++)
            {
                S[i] = S[i - 1] + A[i - 1];
            }

            int count = 0;
            for (int i = A.Length - 1; i >= 0; i--)
            {
                if (A[i] <= 2 * S[i]) count++;
                else { break; }
            }

            count++;
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 29532
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int n;
	int a[80];
	cin >> n;
	rep(i, n)cin >> a[i];

	long long m = 1000;
	rep(i, n - 1) {
		if (a[i] < a[i + 1]) {
			m = m % a[i] + m / a[i] * a[i + 1];
		}
	}

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

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

		long X = sc.nextLong();

		long t = 1;

		while(true){
			if(mySigma(t) >= X)break;
			t++;
		}
		System.out.println(t);
	}

	public static long mySigma(long n){
		return (n * (n + 1)) / 2;
	}
}


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

int main(){
  int t[10];

  for(int i = 0; i < 10; i++){
    cin >> t[i];
  }
  sort(t, t + 10, greater<int>());
  for(int i = 0; i < 3; i++){
    cout << t[i] << endl;
  }
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cstdlib>
#include<ctime>
#include<random>
#define ll long long
using namespace std;

int x;

int main(){
    scanf("%d",&x);
    int ans=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    printf("%d\n",ans);
}

Measured memory_bytes: 3788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);
		
		Line[] lines = new Line[m];
		
		for(int i = 0; i < m; i++){
			tmpArray = br.readLine().split(" ");
			lines[i] = new Line(Integer.parseInt(tmpArray[0]), Integer.parseInt(tmpArray[1]));
			
		}
		
		int[] visited = new int[n + 1];
		int[] finished = new int[n + 1];
		
		int[][] matrix = new int[n + 1][n + 1];
		
		int bridge = 0;
		for(int i = 0; i < m; i++){
			initMatrix(matrix, lines, n, i);
			Arrays.fill(visited, 0);
			Arrays.fill(finished, 0);
			
			dfs(matrix, visited, finished, 1, 0);
			
			for(int j = 1; j <= n ; j++){
				if(visited[j] == 0){
					bridge++;
					break;
				}
			}
		}
		
		System.out.println(bridge);
	}

	static void initMatrix(int[][] matrix, Line[] lines, int n, int skip){
		for(int i = 0; i <= n; i++){
			Arrays.fill(matrix[i], 0);
		}
		
		for(int i = 0; i < lines.length ; i++){
			if(i == skip){
				continue;
			}
			
			matrix[lines[i].start][lines[i].end] = 1;
			matrix[lines[i].end][lines[i].start] = 1;
		}
	}
	static int dfs (int[][] matrix, int[] visited, int[] finished, int v, int time){
        //System.out.println("current vertex is "+v);
        time++;
        visited[v] = time;
         
        int tmpTime = time;
        for(int i = 1; i <= matrix[v].length - 1 ; i++){
            if(matrix[v][i] == 1 && visited[i] <= 0){
                tmpTime = dfs(matrix, visited, finished, i, tmpTime);
            }
        }
         
        finished[v] = tmpTime + 1;
         
        return tmpTime + 1;
    }
}

class Line{
	int start;
	int end;
	
	public Line(int start, int end){
		this.start = start;
		this.end = end;
	}
}

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


using namespace std;


int main()
{
    map<long long, long long>mp;
    long long a,b,c;
    cin>>a>>b>>c;
    for(long long i = 1;i<=a; ++i)mp[i]=b-c;
    while(c--)
    {
        long long q;
        cin>>q;
        mp[q]++;
    }
    for(long long i = 1;i<=a; ++i){
        if(mp[i]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <utility>
#include <functional>
#include <numeric>

//TODO

template <class T>
using vec = std::vector<T>;

constexpr int nil = -1;
constexpr int inf = 1 << 30;

struct Edge
{
    int to;
    int cost;
};

vec<int> dijkstra(const vec<vec<Edge>>& edges)
{
    using namespace std;

    const int n = edges.size();
    vec<int> distances(n, inf);
    vec<bool> reached(n, false);

    distances[0] = 0;

    while (true)
    {
        int minCost {inf};
        int u {};

        for (int i = 0; i < n; ++i)
        {
            if (!reached[i] && distances[i] < minCost)
            {
                minCost = distances[i];
                u = i;
            }
        }

        if (minCost == inf)
            break;
        
        reached[u] = true;

        for (auto& e : edges[u])
        {
            distances[e.to] = min(distances[e.to], distances[u] + e.cost);
        }
    }

    return distances;
}

void solve()
{
    using namespace std;
    int n;
    cin >> n;

    //隣接リスト形式
    vec<vec<Edge>> edges(n);
    
    //入力
    for (int i = 0; i < n; ++i)
    {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j)
        {
            int to, cost;
            cin >> to >> cost;
            edges[i].push_back({to, cost});
        }
    }

    auto d = dijkstra(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i << " " << d[i] << endl;
    }
}

int main()
{
    solve();
    return 0;
}


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

using namespace std;
const int N = 2e5 + 5;
int p[N], mark[N];
vector <int> vec[2], g[N];

void dfs(int v, int p = 0, int c = 0) {
    vec[c].push_back(v);
    for (int u : g[v]) if (u != p) dfs(u, v, c^1);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    if (vec[0].size() <= n/3) {
        for (int i = 0; i < vec[0].size(); i++) p[vec[0][i]] = 3 * i + 3, mark[3 * i + 3] = 1;
        vector <int> V;
        for (int i = 1; i <= n; i++) if (!mark[i]) V.push_back(i);
        for (int i = 0; i < vec[1].size(); i++) p[vec[1][i]] = V[i];
        for (int i = 1; i <= n; i++) cout << p[i] << " ";
        cout << "\n";
        return 0;
    }
    if (vec[1].size() <= n/3) {
        for (int i = 0; i < vec[1].size(); i++) p[vec[1][i]] = 3 * i + 3, mark[3 * i + 3] = 1;
        vector <int> V;
        for (int i = 1; i <= n; i++) if (!mark[i]) V.push_back(i);
        for (int i = 0; i < vec[0].size(); i++) p[vec[0][i]] = V[i];
        for (int i = 1; i <= n; i++) cout << p[i] << " ";
        cout << "\n";
        return 0;
    }
    vector <int> V[2];
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 1) V[0].push_back(i);
        if (i % 3 == 2) V[1].push_back(i);
    }
    for (int i = 3; i <= n; i += 3) {
        if (V[0].size() < vec[0].size()) V[0].push_back(i);
        else V[1].push_back(i);
    }
    for (int i = 0; i < vec[0].size(); i++) p[vec[0][i]] = V[0][i];
    for (int i = 0; i < vec[1].size(); i++) p[vec[1][i]] = V[1][i];
    for (int i = 1; i <= n; i++) cout << p[i] <<  " ";
    cout << "\n";
}


Measured memory_bytes: 23412
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

#include <bits/stdc++.h>
using namespace std;



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

    string t = S;
    reverse(t.begin(),t.end());

    string s1="";
    string s2="";

    if(S == t){
        rep(i,(S.size()-1)/2){
            s1 += S[i]; 
        }
        string s11 = s1;
        rep2(i,(S.size()+3)/2-1,S.size()){
            s2 += S[i]; 
        }
        string s22 = s2;
        reverse(s1.begin(),s1.end());
        reverse(s2.begin(),s2.end());
        if(s1 == s11 && s2 == s22){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
s = str(input())
t = str(input())

len_s = len(s)
len_t = len(t)
best_score = 0
for i in range(len_s-len_t+1):
    obj = s[i:i+len_t]
    score = 0
    for j in range(len_t):
        if obj[j] == t[j]:
            score += 1
    if score > best_score:
        best_score = score
        
print(len_t - best_score)

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 10000100
//#define NIL -1

int main() {
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i=0; i<n; i++){
        cin >> a[i];
    }

    LL x=0;
    LL ans;
    LL min_ans=-1;
    for(LL i=0; i<n; i++){
        x+=a[i];
    }
    x/=n;
    x--;
    for(LL i=x; i<x+3; i++){
        ans=0;
        for(LL j=0; j<n; j++){
            ans=ans+(a[j]-i)*(a[j]-i);
        }
        if(min_ans==-1 || min_ans>ans){
            min_ans=ans;
        }
    }

    cout << min_ans << endl;


    return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

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

    int prev = 0;
    vector<ll> a(S.length() + 1, 0);

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '<') {
            a[i] = 0;
            ll lcnt = 1;
            
            while (S[i + lcnt] == '<') {
                a[i + lcnt] = max(lcnt, a[i + lcnt]);
                lcnt++;
            }

            a[i + lcnt] = max(lcnt, a[i + lcnt]);
            i += lcnt - 1;
        } else {
            ll rcnt = 1;
            
            while (S[i + rcnt] == '>')
                rcnt++;

            ll cnt = 0;
            
            for (int j = i + rcnt; j > i; j--) {
                a[j] = max(cnt, a[j]);
                cnt++;
            }

            a[i] = max(a[i], cnt);
            i += rcnt - 1;
        }
    }
  
  ll ans = 0;
  for (auto e : a) {
    ans += e;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4740