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

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    vector<int> s(D);
    int rest, cnt, plus;
    int ans = INT_MAX;
    
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
        s[i] = (i + 1) * 100;
    }
    
    for (int i = 0; i < (1 << D); i++) {
        bitset<10> b(i);
        rest = G;
        cnt = 0;
        
        for (int ii = 0; ii < D; ii++) {
            if (b[ii]) {
                rest -= s[ii] * p[ii] + c[ii];
                cnt += p[ii];
            }
        }
        
        for (int ii = (D - 1); ii >= 0; ii--) {
            if (!b[ii]) {
                plus = min((max(rest, 0) + s[ii] - 1) / s[ii], p[ii]);
                rest -= plus * s[ii];
                cnt += plus;
            }
        }
        
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int k, n;
  cin>>k>>n;
  int a[n];
  REP(i, n){
    cin>>a[i];
  }
  int md = 0;
  REP(i, n){
    if(i < n - 1){
      md = max(md, a[i+1] - a[i]);
    }else{
      md = max(md, k-a[n-1] + a[0]);
    }
  }
  int ans = k - md;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
class aoj
{
    static void Main()
    {

        int z = int.Parse(Console.ReadLine());
        ulong[] fg = new ulong[z];
        int i = 0;
        for (i = 0; i < z; i++)
        {
            string a = Console.ReadLine();
            char[] c = a.ToCharArray();
            ulong h = 0, k = 0;
            Array.Sort(c);
            string kl = new string(c);
            h = ulong.Parse(kl);
            Array.Reverse(c);
            string hj = new string(c);
            k = ulong.Parse(hj);
            fg[i] = k - h;
        }
        foreach (ulong jl in fg)
        {
            Console.WriteLine(jl);
        }
    }
}

Measured memory_bytes: 9248
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}


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

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//*********************************************************************************************************************************************//

ll dp[105][N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int n,lim;
    cin >> n >> lim;
    ll val[n+1],w[n+1];
    for(int i=0;i<n;i++)
        cin >> w[i+1] >> val[i+1];
    for(int j=1;j<=lim;j++)
    {
        for(int i=1;i<=n;i++)
        {
            if(j-w[i]<0)
            {
                dp[i][j] = dp[i-1][j];
                continue;
            }
            dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i]] + val[i]);
        }
    }
    cout << dp[n][lim];
}


Measured memory_bytes: 79360
import java.util.*;

public class Main {

  public static void main(String[] args) {
  Scanner scan = new Scanner(System.in);
  int a = scan.nextInt();
  int b = scan.nextInt();
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    System.out.println("Possible");
  }else{
    System.out.println("Impossible");
  }
  }
}


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

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

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

    unsigned int N, count = 0;

    cin >> N;

    for(int i=1; i<=N; i++){
        if(GetDigit(i) % 2 != 0)
            count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[int(x) for x in input().split()]

min_ans=100000000000000

for i in range(-200,200):
  ans=0
  for j in range(N):
    ans+=(A[j]-i)**2
  if ans<min_ans:
    min_ans=ans
print(min_ans)
    

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


int main(void){
    int h,w;
    cin >>h >>w;
    char a[h+2][w+2];
    rep(i,h+2){
        rep(j,w+2){
            a[i][j] = '.';
        }
    }
    rep(i,h){
        rep(j,w){
            cin >> a[i+1][j+1];
        }
    }
    bool flag = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int check = 0;
            if(a[i][j]=='#'){
                if(a[i-1][j]=='#'){
                    check++;
                }
                if(a[i][j-1]=='#'){
                    check++;
                }
                if(a[i+1][j]=='#'){
                    check++;
                }
                if(a[i][j+1]=='#'){
                    check++;
                }
                if(check == 0){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag==1){
            break;
        }
    }
    if(flag){
        cout << "No" <<endl;
    }
    else{
        cout << "Yes" <<endl;
    }
    
    
    
    return 0;
}




























































Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;
using LL = long long;

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int INF = 1000000000;

template <typename T> T gcd(T m, T n) {
  if (m < n)
    return gcd(n, m);
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int main() {
  IN(N);

  int g = -1;
  vector<int> A;
  REP(i, N) {
    IN(a);
    A.push_back(a);
    if (g == -1)
      g = a;
    else
      g = gcd(g, a);
  }
  int min_index = 0;
  REP(i, N) {
    A[i] /= g;
    if (A[min_index] > A[i])
      min_index = i;
  }
  int g2 = -1;
  REP(i, N) {
    if (i == min_index)
      continue;
    if (g2 == -1)
      g2 = A[i];
    else
      g2 = gcd(A[i], g2);
  }
  int ans = 0;
  for (int n = 1; n * n <= A[min_index]; ++n) {
    if (A[min_index] % n == 0) {
      int count = 0;
      REP(i, N) {
        if (A[i] % n == 0)
          ++count;
      }
      if (count + 1 == N)
        ans = max(ans, n);

      count = 0;
      REP(i, N) {
        if (A[i] % (A[min_index] / n) == 0)
          ++count;
      }
      if (count + 1 == N)
        ans = max(ans, A[min_index] / n);
    }
  }
  OUT(max(g * g2, g * ans));

  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>

int main() {
  std::string s;
  std::cin >> s;
  if (s.size() <=3) {
    std::cout << "No" << std::endl;
  } else {
    if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
      std::cout << "Yes" << std::endl;
    } else {
      std::cout << "No" << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

fn main() {
  input! {
    k : usize,
  };

  let mut d = 7;
  let mut cur = d % k;
  let mut res = 1;
  loop {
    if cur == 0 || (k % 2 == 0 || k % 5 == 0) {
      break;
    }
    
    d = (d * 10) % k;
    cur = (cur + d) % k;
    res += 1;
  }

  if k % 2 == 0 || k % 5 == 0 {
    println!("-1");
  } else {
    println!("{}", res);
  }
}

Measured memory_bytes: 2164
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner (System.in);

    int times = cin.nextInt();

    HashSet<String> set = new HashSet<>();

    String pre = "";

    for (int i=0;i<times;i++){

      String item = cin.next();

      if (i==0) {
        set.add(item);
        pre = item;
      }
      else {
        if (item.charAt(0)!=pre.charAt(pre.length()-1)) {
          System.out.println("No");
          return;
        }
        else {
          if (set.contains(item)) {
            System.out.println("No");
            return;
          }
          else {
            set.add(item);
            pre = item;
          }
        }
      }
    }

    System.out.println("Yes");

  }


}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string n;
    cin >> n;

    int sum = 0 ;
    for(int i = 0; i < n.size(); i++) {
        sum += n[i] - '0';
    }

    if (sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , ans = 0;
    string s;
    cin >> n >> s;
	for( int i = 1 ; i < n ; i++ ) {
    	int a[26] = {}, b[26] = {} , e = 0;
    	for ( int j = 0 ; j < i ; j++ ) a[s[j] - 'a'] = 1;
        for ( int j = i ; j < n ; j++ ) b[s[j] - 'a'] = 1;
        for ( int j = 0 ; j < 26 ; j++ ) if ( a[j] && b[j] ) e++;
        ans = max( ans , e );
	}
	cout << ans;
}  


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

int main()
{
  int i,j,n,hold,count=0;
  int Array[100];
  
  scanf("%d",&n);
  if( n < 1 || n > 100 )
    exit(1);
  
  for( i = 0; i < n; i++ )
    {
      scanf("%d",&Array[i]);
      if( Array[i] < 0 || Array[i] > 100 )
	exit(1);	
    }
  
  for( i = 0; i < n-1; i++ )
    {
      for( j = n-1; j > i; j-- )
	{
	  if(Array[j] < Array[j-1])
	    {
	      hold = Array[j];
	      Array[j] = Array[j-1];
	      Array[j-1] = hold;
	      count++;
	    }
	}
    }
 
  for( i = 0; i <= n-2; i++ )
    printf("%d ",Array[i]);
  printf("%d\n",Array[n-1]);
  printf("%d\n",count);

  return 0;
}



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

using ll=long long; 

void solve(){
	int k,s;
	cin>>k>>s;
	int cnt=0;
	for(int i=0; i<k+1; i++){
		for(int j=0; j<k+1; j++){
			int z=s-i-j;
			if(z<=k && z>=0){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    H = list(map(int,input().split()))

    if N == 1:
        print("Yes")
        return

    pre_h = H[0]
    for _, h in enumerate(H):
        if h == pre_h:
            continue
        elif h > pre_h:
            pre_h = (h - 1)
            continue
        print("No")
        return
    
    print("Yes")
    return


if __name__ == "__main__":
    solve()


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

#define llint long long

using namespace std;

signed main() {
	llint n;
	cin >> n;

	llint count = 0;

	for(llint a = 2; a * a <= 10e12; a++){
		if(n % a != 0){
			continue;
		}

		llint e = 0;
		while(n % a == 0){
			e++;
			n /= a;
		}

		llint j = 1;
		while(e >= j){
			e -= j;
			j++;
			count++;
		}
	}

	if(n != 1){
		count++;
	}

	cout << count << endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#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;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n, x; cin>>n>>x;
    if(x == 1 || x == 2 * n - 1){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    vector<int> v;
    for(int i=1; i<=2*n-1; i++){
        if(i == x - 1 || i == x || i == x + 1) continue;
        v.emplace_back(i);
    }

    for(int i=0; i<n-2; i++){
        cout << v[i] << endl;
    }
    for(int i=x-1; i<=x+1; i++){
        cout << i << endl;
    }
    for(int i=n-2; i<2*n-4; i++){
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  vector<ll>v(n+1,0);
  for(ll i=1;i<n+1;i++){
    v[i]=v[i-1];
    if(s[i-1]=='#')v[i]+=1;
  }
  ll ans=999999999999;
  if(v[n]==n||v[n]==0){
    cout<<0<<endl;
    return 0;
  }
  for(ll i=0;i<n;i++){
    ll tmp=0;
    if(s[i]=='.'){
      tmp=1;
    }
    tmp+=v[i];
    tmp+=(n-i-1)-(v[n]-v[i+1]);
    ans=min(ans,tmp);
  }
  ans=min(ans,v[n]);
  cout<<ans<<endl;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n;
long long dp[105][4][4][4],ans;

int main()
{
	cin >> n;
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			for(int k = 0; k < 4; k++){
				if(i == 0 && j == 1 && k == 2) continue;
				if(i == 0 && j == 2 && k == 1) continue;
				if(i == 1 && j == 0 && k == 2) continue;
				dp[3][i][j][k] = 1;
			}
	for(int i = 4; i <= n; i++){
		for(int x = 0; x < 4; x++)
			for(int y = 0; y < 4; y++)
				for(int z = 0; z < 4; z++)
					for(int k = 0; k < 4; k++){
						if(y == 0 && z == 1 && k == 2) continue;
						if(y == 0 && z == 2 && k == 1) continue;
						if(y == 1 && z == 0 && k == 2) continue;
						if(x == 0 && z == 1 && k == 2) continue;
						if(x == 0 && y == 1 && k == 2) continue;
						dp[i][y][z][k] += dp[i-1][x][y][z];
						dp[i][y][z][k] %= MOD;
					}
	}
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			for(int k = 0; k < 4; k++)
				ans = (ans + dp[n][i][j][k]) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;

inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}

int main(){
  int n = getint(), k = getint();
  if(k == 1) puts("0");
  else printf("%d\n",n - k);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n % 2 == 0){
    int a = n / 2;
    cout << a * a << "\n";
    return 0;
  }
  int b = n / 2;
  int c = b + 1;
  cout << b * c << "\n";
}


Measured memory_bytes: 3600
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(1, N):
  if (X[i]-X[i-1]) * A < B:
    ans += (X[i]-X[i-1]) * A
  else:
    ans += B
print(ans)

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; --i)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n){
        cin >> s[i];
    }
    bool dp[101][10001];
    dp[0][0] = true;
    REP(i, 1, n+1){
        rep(j, 10001){
            if(j >= s[i-1]){
                dp[i][j] = dp[i-1][j] || dp[i-1][j-s[i-1]];
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    int ans = 0;
    repr(j, 10001){
        if(j % 10 == 0){
            continue;
        }
        if(dp[n][j]){
            ans = j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
}



Measured memory_bytes: 3612
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;

ll max_rec(vl v, ll i, ll n)
{
    if(i>=n)
        return 0;
    else
        return max(max_rec(v,i+2,n) + v[i], max_rec(v,i+1,n));
}


int main()
{
    SYNC
    //clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string s,s1; in(s)>>s1;
    ll n=s.size();
    ll m=s1.size();
    ll ans = 1000000;
    for(ll i=0; i<n-m+1; i++)
    {
        ll temp=0;
        for(ll j=0; j<m; j++)
        {
            if(s[i+j] != s1[j])
                temp++;
        }
        ans=min(temp,ans);
    }
    o(ans)<<endl;









    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


Measured memory_bytes: 3656
import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for a_idx in range(N-2):
        for b_idx in range(a_idx+1, N-1):
            l_idx = b_idx + 1
            r_idx = bisect.bisect_left(L, L[a_idx] + L[b_idx])
            ans += r_idx - l_idx
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73968
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 62
char Fix(int t)
{
	if (t < 10)
		return '0' + t;
	t -= 10;
	if (t < 26)
		return 'a' + t;
	t -= 26;
	return 'A' + t;
}
string s[N];
int sum = N, tim;
int Query(string s)
{
	if (s.length() > 128)
		return 0x3f3f3f3f;
	++tim;
	if (tim >= 850)
		while (1);
			cout << "?" << " " << s << endl;
	fflush(stdout);
	int ans = 0;
	cin >> ans;
	return ans;
}
int len = 0x3f3f3f3f, q[N];
string Merge(string a, string b)
{
	int i = 0, j = 0;
	int la = a.length(), lb = b.length();
	string ret = string();
	while (i < la && j < lb)
	{
		string qr = ret;
		qr += a[i];
		for (int k = j; k < lb; k++)
			qr += b[k];
		if (Query(qr) + qr.length() == len)
			ret += a[i++];
		else
			ret += b[j++];
	}
	while (i < la)
		ret += a[i++];
	while (j < lb)
		ret += b[j++];
	return ret;
}
int main()
{
	for (int i = 0; i < N; i++)
	{
		s[i] += Fix(i);
		q[i] = Query(s[i]) + 1;
		len = min(len, q[i]);
	}
	for (int i = 0; i < N; i++)
	{
		if (q[i] == len)
			while (Query(s[i] + Fix(i)) + s[i].length() + 1 == len)
				s[i] += Fix(i);
		else
			s[i] = string();
	}
	while (1)
	{
		for (int i = 0; i < N; i++)
			for (int j = i + 1; j < N; j++)
				if (s[i].length() > s[j].length())
					swap(s[i], s[j]);
		int t = 0;
		while (!s[t].length())t++;
		if (t + 1 == N)
			break;
		string now = Merge(s[t], s[t + 1]);
		s[t + 1] = now;
		s[t] = string();
	}
	cout << "! "<< s[N - 1] << endl;
	fflush(stdout);
}
//

Measured memory_bytes: 3780
sa = list(input())
sb = list(input())
sc = list(input())

sa.append('A')
sb.append('B')
sc.append('C')

def solve(s):
    if len(s) > 1:
        buf = s[0]
        del s[0]
        if buf == 'a':
            solve(sa)
        elif buf == 'b':
            solve(sb)
        else:
            solve(sc)
    else:
        print(s[0])
        return

solve(sa)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[334334],cnt[334334];int n,memo=0,ans=0,cnta=0;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		memo+=a[i];
		cnt[i]=memo;
	}
	sort(cnt,cnt+n);
	rep(i,n){
		if(cnt[i]==0)cnta++;
	}
	rep(i,n){
		if(i != n-1 && cnt[i]==cnt[i+1])continue;
		ans+=(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i]))*(upper_bound(cnt,cnt+n,cnt[i])-lower_bound(cnt,cnt+n,cnt[i])-1)/2;
	}
	cout<<ans+cnta<<endl;
}

Measured memory_bytes: 3968
import java.util.*;
public class Main {
    static int MOD = 100;
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int rowNum = sc.nextInt();
        int colNum = sc.nextInt();
        char[][] grid = new char[rowNum][colNum];
        for(int i = 0; i < rowNum; i++)
            grid[i] = sc.next().toCharArray();

        int steps = bfs(grid, rowNum, colNum);
        if(steps == -1) {
            System.out.println(steps);
            return;
        }
        int blackCnt = 0;
        for(int i = 0; i < rowNum; i++) {
            for(char c : grid[i]) {
                if(c == '#')
                    blackCnt++;
            }
        }
        System.out.println(rowNum * colNum - blackCnt - steps);
    }

    private static int bfs(char[][] grid, int rowNum, int colNum) {
        int[] rows = new int[]{-1, 1, 0 , 0};
        int[] cols = new int[]{ 0, 0, -1, 1};

        Queue<Integer> queue = new LinkedList<>();
        queue.offer(0);

        boolean[][] visited = new boolean[rowNum][colNum];
        visited[0][0] = true;

        int curRow = 0, curCol = 0;
        int nextRow = 0, nextCol = 0;
        int steps = 1;
        while(!queue.isEmpty()) {
            int size = queue.size();
            for(int i = 0; i < size; i++) {
                int pos = queue.poll();
                if(pos / MOD == rowNum - 1 &&  pos %  MOD == colNum - 1) {
                    return steps;
                }
                curRow = pos / MOD;
                curCol = pos % MOD;
                for(int j = 0; j < rows.length; j++) {
                    nextRow = curRow + rows[j];
                    nextCol = curCol + cols[j];
                    if(isValid(grid, visited, nextRow, nextCol)) {
                        queue.offer(nextRow * MOD + nextCol);
                    }
                }
            }
            steps++;
        }
        return -1;
    }

    private static boolean isValid(char[][] grid, boolean[][] visited, int row, int col) {
        if(row < 0 || row >= grid.length || col < 0 || col >= grid[row].length || 
        visited[row][col] || grid[row][col] == '#')
            return false;
        visited[row][col] = true;
        return true;
    }
}


Measured memory_bytes: 23892
use std::io::*;
use std::str::*;
use std::collections::HashMap;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut map: HashMap<usize, usize> = HashMap::new();

    for _ in 1..n {
        let key: usize = read().unwrap();
        let count = map.entry(key).or_insert(0);
        *count += 1;
    }
    for n_i in 1..n + 1 {
        let check = map.get(&n_i);
        match check {
            Some(n) => println!("{}", n),
            None => println!("0")
        };
    }

    /*    for (key_i, value_i) in map.iter() {
            println!("{} {}", key_i, value_i);
        }*/
}


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

int main()
{
	int a, b;

	while (cin >> a >> b) {
		int s = a + b, t = 0;

		while (s > 0) {
			s /= 10;
			t++;
		}

		cout << t << endl;
	}

	return 0;
}


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

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back


int main(){
   
    int n;
    cin>>n;

    cout<<"ABC"<<n<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    vector<ll> sumL(n), sumR(n);
    sumL[0] = a[0];
    for(int i = 1; i < n; i++) {
        sumL[i] = sumL[i-1] + a[i];
    }
    sumR[n-1] = a[n-1];
    for(int i = n-2; i >= 0; i--) {
        sumR[i] = sumR[i+1] + a[i];
    }

    ll res = INF;
    for(int i = 0; i < n-1; i++) {
        res = min(res, abs(sumL[i] - sumR[i+1]));
    }

    cout << res << endl;

    return 0;
}

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

int main(){
  string S,T,U;
  int A,B;
  cin>>S>>T>>A>>B>>U;
  if(S==U){
    cout<<A-1<<" "<<B<<endl;
  }
  if(T==U){
    cout<<A<<" "<<B-1<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000
int main(){
  int a,b,A[MAX]={-1},B[MAX],count=0,i,j,c=1,t;
  scanf("%d",&a);
  scanf("%d",&A[0]);
  for(i=1;i<a;i++){
    scanf("%d",&t);
    if(A[c-1]<t){A[c]=t;c++;}
  }

  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
  }
  i=c;
  for(i=0;i<b;i++){
    for(j=0;j<a;j++){
      if(A[j]==B[i]){count++;break;}
      if(A[j]>B[i]){break;}
    }
  }
  printf("%d\n",count);
  return 0;
}
///

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int r[100]={},c[100]={};
int main(){
  int H,W;
  cin>>H>>W;
  string str[100];
  int i=0,j=0;
  while(i<H){
    j=0;
    cin>>str[i];
    while(j<W){
      if(str[i][j]=='#'){
      r[i]++;
      c[j]++;}
      j++;
    }
    i++;
  }
  i=0;
  while(i<H){
    j=0;if(!r[i]){i++;continue;}
    while(j<W){
      if(c[j])cout<<str[i][j];
      j++;
    }
    i++;
    cout<<endl;
  }
}

Measured memory_bytes: 256
/** author: __nishad **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979323

int main()
{
    IOS;

    ll n, t, a, com=1e6, i=1;
    vector<tuple<double, double>> v;
    cin>>n>>t>>a;

    while(n--){
        double x ;
        cin>>x;
        x = t - double(x * 0.006);

        v.pb(make_tuple(fabs(a-x), i));
        i++;
    }

    sort(all(v));

    cout<<get<1>(v[0]);


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<queue>
#define poi 2001000
#define int long long
using namespace std;
bool b[poi];
inline int re()
{
	char c=getchar();
	int x=0,k=1;
	while(c<'0'||c>'9')
	{if(c=='-')k=-1;c=getchar();}
	while(c>='0'&&c<='9')
	{x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return x*k;
}
void wr(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) wr(x/10);
	putchar(x%10+'0');
}
signed main()
{
	int ans=0,n=0,c,sum=0;
	while((c=getchar())!='\n')
	b[++n]=(c=='B');
	for(int i=1;i<=n;i++)
	if(!b[i]) ans+=sum;
	else sum++;
	wr(ans);
	return 0;
}

Measured memory_bytes: 384
#include<string>
#include<iostream>
#include<deque>
#include<cstdlib>
#include<algorithm>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define rep(i, x, n) for(i=x;(i)<(n);(i)++)

const int MOD = 1000000007;
const int infty = 1000000000;

typedef struct Day {
	lli first;
	lli second;
	lli third;
	lli max() { return std::max(first, std::max(second, third)); }
};

int main() {
	int n;
	cin >> n;
	deque<Day> dp(n, {0, 0, 0}), nodes;
	int i;
	rep(i, 0, n) {
		lli a,b,c;
		cin >> a >> b >> c;
		nodes.push_back({ a,b,c });
	}
	rep(i, 0, n) {
		if (i == 0) {
			dp[i] = nodes[i];
			continue;
		}
		else {
			lli first = std::max(dp[i - 1].second + nodes[i].first, dp[i - 1].third + nodes[i].first);
			lli second = std::max(dp[i - 1].third + nodes[i].second, dp[i - 1].first + nodes[i].second);
			lli third = std::max(dp[i - 1].first + nodes[i].third, dp[i - 1].second + nodes[i].third);
			dp[i] = { first, second, third };
		}
	}
	cout << dp[n - 1].max() << endl;
	return 0;
}

Measured memory_bytes: 8440
/* Which of the favors of your Lord will you deny? */

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

#define pi       acos(-1)

#define SI(n)    scanf("%d",&n)
#define SLL(n)   scanf("%lld",&n)
#define SULL(n)   scanf("%llu",&n)
#define SC(n)    scanf("%c",&n)
#define SD(n)    scanf("%lf",&n)

#define fr(i,a,b) for(int i=a ,_b=(b) ;i<= _b;i++)

#define LL      long long
#define PUB     push_back
#define POB     pop_back
#define MP      make_pair;
#define PII     pair<int,int>
#define PLL     pair<ll,ll>

#define GCD     __gcd
#define DEBUG   cout<<"aw"<<endl;

unsigned LL bigMod(int x,int n,int mo)
{
    if(n==0)
        return 1;

    unsigned LL u = bigMod(x,n/2,mo);
    u = ((u%mo)*(u%mo))%mo;

    if(n%2==1)
        u = ((u%mo)*(x%mo))%mo;

    return u;
}

int ara[100010];
int cntara[100010];

int main()
{
    int n;
    SI(n);

    fr(i,1,n)
    {
        SI(ara[i]);
    }

    sort(ara+1,ara+n+1);

    int flag=0,cntzero=0;

    if(n%2==0) // n%2==0
    {
        fr(j,1,n)
        {
            if(ara[j]==0)
            {
                flag = 1;
                break;

            }

            if((ara[j]%2==1)&&(ara[j]<n))
            {
                if(ara[j]==ara[j+1])
                {
                    cntara[ara[j]]++;
                    //DEBUG

                }


                if(cntara[ara[j]]+1>2)
                {
                    flag = 1;
                    break;
                }

            }
            else
            {
                flag = 1;
                break;

            }

        }

    }

    else if(n%2==1) // n%2==1
    {
        fr(j,1,n)
        {
            if(ara[j]==0)
            {
                cntzero++;

                if(cntzero>1)
                {
                    flag=1;
                    break;

                }

            }


            if((ara[j]%2==0)&&(ara[j]<n))
            {
                if(ara[j]==ara[j+1])
                    cntara[ara[j]]++;

                if(cntara[ara[j]]+1>2)
                {
                    flag = 1;
                    break;
                }

            }
            else
            {
                flag = 1;
                break;

            }

        }

    }

    //fr(qq,1,n)
    //  printf("**%d\n",cntara[qq]);



    if(flag==1)
    {
        printf("0\n");
        return 0;
    }

    int cntans = 0;

    fr(w,1,n)
    {
        if(cntara[w]+1==2)
            cntans++;
    }

    int mo = 1000000007;

    unsigned LL ans = bigMod(2,cntans,mo);

    printf("%llu\n",ans);

    return 0;
}



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

class Program {
  static void Main(string[] args) {
  	while(true) {
  	int n = int.Parse(Console.ReadLine());
  	if(n == 0) break;
  	var seq = Console.ReadLine().Split(' ').Select(x => double.Parse(x));
  	double avr = seq.Average();
  	double variance = seq.Select(x => (x - avr) * (x - avr)).Sum() / n;
  	Console.WriteLine(Math.Sqrt(variance));
  	}
  }
}

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

const int MAXN = 2e7 + 5;
const int MOD = 1e9 + 7;

int H, W, K;
int sum, tot;

void load() {
	scanf("%d%d%d", &H, &W, &K);
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

inline int mul(int x, int y) {
	return (long long)x * y % MOD;
}

int range(int lo, int hi) {
	int res = 1;
	for (int i = lo + 1; i <= hi; i++)
		res = mul(res, i);
	return res;
}

int solve() {
	tot = mul(mul(K, K + 3), (MOD + 1) / 2);
	for (int i = 1; i < K; i++)
		sum = add(sum, mul(i, K - i));
	sum = mul(sum, 2);
	
	return add(mul(tot, range(H + W - K, H + W)), mul(sum, mul(mul(H, W), range(H + W - K, H + W - 2))));
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 256
n, L = map(int, raw_input().split())
dp = [0] * (n+2)
l = [0]
for i in range(n):
    l += [input()]
    dp[i+1] = L - l[i+1]
l += [0]
for i in range(1,n+1):
    if l[i] < l[i-1]: dp[i] += dp[i-1]
ans = 0
for i in range(n,0,-1):
    if l[i] < l[i+1]:
        dp[i] = max(dp[i], dp[i+1] + (L - l[i]))
    ans = max(ans, dp[i])
print ans

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

void solve(string line){
    char buffer[2100];
    int p = 1025;
    int l = p, r = p;
    buffer[p] = line[0];
    for ( int i = 3; i < line.size(); i+=3 ){
        if ( line[i-1] == '>' ) p++;
        else p--;
        buffer[p] = line[i];
        l = min(l, p); r = max(r, p);
    }
    for ( int i = l; i <= r; i++ ) cout << buffer[i];
    cout << endl;
}

main(){
    int tcase; cin >> tcase;
    string line;
    for ( int i = 0; i < tcase; i++ ) { cin >> line; solve(line); }
}




Measured memory_bytes: 3016
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x):#約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x):#素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  x=[[0 for _ in range(n)] for _ in range(n)]
    n=int(input())
    a=int(input())
    b=int(input())
    c=int(input())
    d=int(input())
    e=int(input())
    m=min(a,b,c,d,e)
    mm=n//m
    if n%m!=0:
        mm+=1
    print(mm+4)
main()

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
    int n, l;
    cin >> n >> l;
    int ans = INF, sum = 0;
    VI a;
    FOR(i, n) {
        a.push_back(l+i);
        sum += l+i;
    }
    int h;
    FOR(i, n) {
        if (chmin(ans, abs(sum-sum+a[i])))h = i;
    }
    cout << sum-a[h] << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;

	int odd = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		if (a % 2 != 0) {
			++odd;
		}
	}

	if (odd != 0) {
		cout << "first" << endl;
	}
	else {
		cout << "second" << endl;
	}
}


Measured memory_bytes: 384
/**
 *   author: bholuakku
 *   prob: A
**/

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long> h(n), dp(n);
    for(auto &it : h) cin>>it;
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2; i<n; i++){
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
//ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INF ? -1 : cost[i])<<'\n';
  }
  return(0);
}


Measured memory_bytes: 8056
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long n , ans = 0 , f = 10;
  cin>>n;

  if(n % 2 == 0){
    while(n>=f){
      ans+=(n/f);
    f*=5;
    }
  }
  
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int w,c,d,e,f;
    
    scanf("%d", &c);
    scanf("%d", &d);
	 
	 
	 e = c - 1;
	 f = d - 1;
	 w = e * f ;
	 printf("%d", w);
	
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,c=0,i,k;
    cin>>n>>m;
    int a[n+10];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        c+=a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    k = c/(4*m);
    if(c%(4*m)!=0)
    {
        k++;
    }
    for(i=0; i<m; i++)
    {
        if(a[i]<k)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define maxn -20000000000 //negative value to break code and force you to put right constraint
#define mod 1073741824
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 100000000000
#define INFd 1e9
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

map<pair<ll,ll>,ll> m;
ll ans=0;
vector<ll> adj[100005];
vector<bool> vis(100005,false);
void dfs(ll s,ll cnt)
{
	vis[s]=true;
	ll c=1;
	for(ll i=0;i<adj[s].size();i++)
	{
		if(c==cnt)
		{
			c++;
		}
		ll x=adj[s][i];
		if(!vis[x])
			{
				ans=max(ans,c);
				m[mp(x,s)]=c;
				m[mp(s,x)]=c;
				dfs(x,c);c++;}

	}
}

int main()
{		
	ll n;
	cin>>n;
	vector<pair<ll,ll> > v(n);
	for(ll i=0;i<n-1;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[i].fi=x;
		v[i].se=y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(ll i=1;i<=n;i++)
	{
		if(!vis[i])
			dfs(i,0);
	}
	cout<<ans<<endl;
	for(ll i=0;i<n-1;i++)
	{
		cout<<m[mp(v[i].fi,v[i].se)]<<endl;
	}
	
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, T;
    cin >> N >> T;
    int64_t ans = 0, x = 0, y = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        ans += min(x - y, T);
        y = x;
    }
    cout << ans + T;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,cnt=0;
	string a;
	cin>>k>>a;
	a.push_back('w'),a.push_back('w');
	for(int i=0;i<a.size();i++){
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')cnt++;
	}
	cout<<cnt;
}

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

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)

int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll n,a,b; cin >> n  >> a >> b;
 long long res = 0;
  res += (n / (a+b)) * a + min(n % (a+b), a);
  cout << res << endl;

}


Measured memory_bytes: 3636
n,m = gets.chomp.split(" ").map{|item| item.to_i}
c = gets.chomp.split(" ").map{|item| item.to_i}
t = Array.new(n,50000)
t.unshift(0)
for i in 0..(m-1) do
	for j in c[i]..n do
		t[j] = (t[j] <= t[j-c[i]]+1) ? t[j] : t[j-c[i]]+1
	end
end
print("#{t[n]}\n")

Measured memory_bytes: 9300
maps = input()
people = [0] * len(maps)

counter = 0
for i in range(len(maps)):
    if maps[i] == 'R':
        counter += 1
        if maps[i+1] == 'L':
            people[i] += (counter+1) // 2
            people[i+1] += counter // 2
    else:
        counter = 0

counter = 0
for i in range(len(maps) - 1, 0, -1):
    if maps[i] == 'L':
        counter += 1
        if maps[i-1] == 'R':
            people[i] += (counter+1) // 2
            people[i-1] += counter // 2
    else:
        counter = 0

print(*people)


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


int main(){
    string s;
    cin >> s;
    int64_t ans = 0;

    if(s.at(0) == 'S'){
        if(s.at(1) == 'S'){
            if(s.at(2) == 'S'){
                ans = 0;
            }else{
                ans = 1;
            }
        }else{
            if(s.at(2) == 'S'){
                ans = 1;
            }else{
                ans = 2;
            }

        }
    }else{
        if(s.at(1) == 'S'){
            if(s.at(2) == 'S'){
                ans = 1;
            }else{
                ans = 1;
            }
        }else{
            if(s.at(2) == 'S'){
                ans = 2;
            }else{
                ans = 3;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3528
# -*- coding: utf-8 -*-
from __future__ import print_function


def rec(a, b):
    """a * x + b * y = gcd(a, b) ??¨??????????????? (x, y, gcd) ?????????"""
    assert a >= b
    q, r = divmod(a, b)
    if r == 0:
        return 0, 1, b
    x, y, gcd = rec(b, r)
    # a = b * q + r
    # b * x + r * y = gcd
    # a * y + b * (x - q * y) = gcd
    return y, x - q * y, gcd


a, b = [int(_) for _ in raw_input().split()]

if a < b:
    y0, x0, gcd = rec(b, a)
else:
    x0, y0, gcd = rec(a, b)

# -a/gcd * (x - x0) = b/gcd * (y - y0)
# x = x0 + (b/gcd) * k, y = y0 + (-a/gcd) * k
dx = b // gcd
dy = -a // gcd
if dx < 0:
    dx = -dx
    dy = -dy
x = x0
y = y0
mag = abs(x) + abs(y)

while True:
    x1 = x + dx
    y1 = y + dy
    mag1 = abs(x1) + abs(y1)
    if mag1 >= mag:
        break
    mag = mag1
    x = x1
    y = y1

while True:
    x1 = x - dx
    y1 = y - dy
    mag1 = abs(x1) + abs(y1)
    if mag1 > mag:
        break
    mag = mag1
    x = x1
    y = y1

print(x, y)

Measured memory_bytes: 6424
def main(args):
	user_input = str(input())
	x = int((len(user_input)-1)/2)
	y = int((len(user_input)+3)/2)
	if len(user_input) < 3 or len(user_input) > 99:
		print("No")
	else:
		modx_ui = user_input[0:x]
		mody_ui = user_input[y-1:]
		if user_input == user_input[::-1] and modx_ui == modx_ui[::-1] and mody_ui == mody_ui[::-1]:
			print("Yes")
		else:
			print("No")
  

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

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

int main(void) {
    int N, K;
    cin >> N >> K;
    set<int> D;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        D.insert(d);
    }

    for (int i = N; i <= 10 * N; i++) {
        bool flag = true;
        int tmp = i;
        while (tmp > 0) {
            int digit = tmp % 10;
            if (D.find(digit) != D.end()) {
                flag = false;
                break;
            }
            tmp /= 10;
        }
        if (flag) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256