akhauriyash/Code-Regression huggingface dataset:
import math

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, k = map(int, input().split())
r = n - k
mod = 10 ** 9 + 7
for i in range(1, k + 1):
    if i > r + 1:
        print(0)
    else:
        if i == 1 or i == k:
            print(nCr(r + 1, i) % mod)
        else:
            print(nCr(r + 1, i) * (nCr(k - 1, i - 1)) % mod)

Measured memory_bytes: 3316
n, m = gets.chomp.split(" ").map(&:to_i)
edges = []
m.times do
    edges << gets.chomp.split(" ").map(&:to_i)
    edges[-1][2] = -1 * edges[-1][2]
end

dist = Array.new(n,Float::INFINITY)
dist[0] = 0

(n-1).times do
    edges.each do |e|
        if dist[e[1]-1] > dist[e[0]-1] + e[2]
            dist[e[1]-1] = dist[e[0]-1] + e[2]
#            p dist
        end
    end
end

ans = dist[n-1] * -1
neg = Array.new(n, false)

n.times do
    edges.each do |e|
        if dist[e[0]-1] + e[2] < dist[e[1]-1]
            dist[e[1]-1] = dist[e[0]-1] + e[2]
            neg[e[1]-1] = true
        end

        neg[e[1]-1] = true if neg[e[0-1]] == true
    end
end

if neg[n-1]
    puts "inf"
else
    puts ans
end

Measured memory_bytes: 2172
x, y, a, b, c = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

t = 0
s = 0

A = A[-x:]
B = B[-y:]

C.extend(A)
C.extend(B)
C = sorted(C)

print(sum(C[-x-y:]))

Measured memory_bytes: 113832
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
	
    ll a,d;
    long double b;
    cin>>a>>b;
    d=(ll)(b*100+.001);
    cout<<a*d/100;

End;
}


Measured memory_bytes: 3748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>;
using namespace std;
char s[100010];
int main(){
    scanf("%s",&s);
    int k=strlen(s);
    if(k%2!=0){
        printf("No");
        return 0;
    }
    for(int i=0;i<k/2;i++){
        int u=abs(s[i]-s[k-i-1]);
        if(u!=1&&u!=2){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i <= _##i poi i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi i < _##i poi i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i >= _##i poi i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi i > _##i poi i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

using namespace std;

template<class T> T lov_yet(T t){
    if(t) return t poi
    else return 0 poi
}

template<class T> T gcd(T a, T b){
    if(b) return gcd(b, a % b) poi
    else return a poi
}

int main(){
    string pyon poi
    cin >> pyon poi
    reverse(pyon.begin(), pyon.end()) poi
    cout << pyon poipoi poi
    return 0 poi
}

Measured memory_bytes: 1156
def BFS(n,path):
  """頂点数nと隣接リストpathを与え、連結かどうかをチェックする"""
  check=[0]*n
  check[0]=1
  Que=[0]
  while Que:
    u=Que.pop(-1)
    for v in path[u]:
      if check[v]==0:
        check[v]=1
        Que.append(v)
  if check!=[1]*n: return 1
  else: return 0

N,M=map(int,input().split())
A=[]
B=[]
for i in range(M):
  a,b=map(int,input().split())
  A+=[a-1]
  B+=[b-1]
ans=0
for i in range(M):
  edges=[[] for i in range(N)]
  for j in range(M):
    if j!=i:
      edges[A[j]]+=[B[j]]
      edges[B[j]]+=[A[j]]
  ans+=BFS(N,edges)
print(ans)

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 1'000'000 + 5;

i64 T;

i64 k, a, b;

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> k >> a >> b;

    for (i64 i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3652
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

alias P = Tuple!(long, "i", long, "p");

void main()
{
    auto N = readln.chomp.to!long;
    auto ii = new long[](N+1);
    foreach (i, p; readln.split.to!(long[])) ii[p] = i.to!long+1;
    auto T = redBlackTree(0, ii[N], N+1);
    long res;
    foreach_reverse (p; 1..N) {
        auto x = ii[p];
        {
            auto l = x;
            auto r = T.upperBound(x).front;
            if (r != N+1) {
                auto ll = T.lowerBound(l).back;
                auto rr = T.upperBound(r).front;
                res += (l-ll) * (rr-r) * p;
            }
        }
        {
            auto r = x;
            auto l = T.lowerBound(x).back;
            if (l != 0) {
                auto ll = T.lowerBound(l).back;
                auto rr = T.upperBound(r).front;
                res += (l-ll) * (rr-r) * p;
            }
        }
        T.insert(x);
    }
    writeln(res);
}

Measured memory_bytes: 11484
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

    char buf[200000];
    unsigned long long int sum = 0;
    scanf("%s",buf);
    
    int offset = 0;
    while(buf[offset] != '\0'){
        sum += ((unsigned long long int)(buf[offset] - 48));
        offset++;
    }

    if(sum%9 == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1788
import sys
input = sys.stdin.buffer.readline
import collections
import copy

def main():
    N = int(input())
    a = list(map(int,input().split()))
    c = collections.Counter(a)
    t = c.most_common()[0][0]
    pos = []
    for i in range(N+1):
        if a[i] == t:
            pos.append(i)
            
    l,r = pos
    MOD = 10**9+7
    fac = [0 for _ in range(N+2)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,N+2):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD
        
    def coef(x,y):
        if x < y:
            return 0
        else:
            num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)
            return num
    
    for i in range(N+1):
        i += 1
        al = coef(N+1,i)
        dup = coef(N-r+l,i-1)
        print((al-dup)%MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27456
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans=MOD*MOD;
    forn(i,0,N)
    {
        int temp=2*i*c;
        if(x-i>0)temp+=(x-i)*a;
        if(y-i>0)temp+=(y-i)*b;
        ans=min(ans,temp);
    }
    cout<<ans;

     return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();


        static void Main(string[] args)
        {
            string day = ReadString();

            if(day == "SUN")
            {
                Console.WriteLine("7");
            } else if(day == "MON")
            {
                Console.WriteLine("6");

            }
            else if (day == "TUE")
            {
                Console.WriteLine("5");

            }
            else if (day == "WED")
            {
                Console.WriteLine("4");

            }
            else if (day == "THU")
            {
                Console.WriteLine("3");

            }
            else if (day == "FRI")
            {
                Console.WriteLine("2");

            }
            else if (day == "SAT")
            {
                Console.WriteLine("1");

            }

        }


        public static long nCm(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            var a = n * nCm(n - 1, m - 1) / m;
            return a % 1000000007;
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


Measured memory_bytes: 11220
// 2013/06/28 Tazoe

#include <iostream>
using namespace std;

struct square{
	int w0;		// 上の壁
	int w1;		// 下の壁
	int w2;		// 左の壁
	int w3;		// 右の壁
};

int main()
{
	while(true){
		int w, h;
		cin >> w >> h;

		if(w==0&&h==0)
			break;

		struct square M[30][30];
		for(int y=0; y<h; y++){
			M[y][0].w2 = M[y][w-1].w3 = 1;
		}
		for(int x=0; x<w; x++){
			M[0][x].w0 = M[h-1][x].w1 = 1;
		}

		for(int i=0; i<2*h-1; i++){
			if(i%2==0){
				for(int j=0; j<w-1; j++){
					int b;
					cin >> b;

					M[i/2][j].w3 = M[i/2][j+1].w2 = b;
				}
			}
			else{
				for(int j=0; j<w; j++){
					int b;
					cin >> b;

					M[i/2][j].w1 = M[i/2+1][j].w0 = b;
				}
			}
		}
/*
		for(int y=0; y<h; y++){
			for(int x=0; x<w; x++){
				cout << M[y][x].w0*8+M[y][x].w1*4+M[y][x].w2*2+M[y][x].w3 << ' ';
			}
			cout << endl;
		}
*/
		int D[30][30];
		bool V[30][30];
		for(int y=0; y<h; y++){
			for(int x=0; x<w; x++){
				D[y][x] = 1000;
				V[y][x] = false;
			}
		}

		D[0][0] = 1;

		while(true){
			int D_min = 1000;
			int y_min = -1;
			int x_min = -1;

			for(int y=0; y<h; y++){
				for(int x=0; x<w; x++){
					if(V[y][x])
						continue;

					if(D[y][x]<D_min){
						D_min = D[y][x];
						y_min = y;
						x_min = x;
					}
				}
			}

			if(D_min==1000)
				break;

			V[y_min][x_min] = true;

			if(y_min==h-1 && x_min==w-1)
				break;

			int D1 = D[y_min][x_min]+1;
			if(M[y_min][x_min].w0==0 && D[y_min-1][x_min]>D1){
				D[y_min-1][x_min] = D1;
			}
			if(M[y_min][x_min].w1==0 && D[y_min+1][x_min]>D1){
				D[y_min+1][x_min] = D1;
			}
			if(M[y_min][x_min].w2==0 && D[y_min][x_min-1]>D1){
				D[y_min][x_min-1] = D1;
			}
			if(M[y_min][x_min].w3==0 && D[y_min][x_min+1]>D1){
				D[y_min][x_min+1] = D1;
			}
		}

		if(V[h-1][w-1]){
			cout << D[h-1][w-1] << endl;
		}
		else{
			cout << 0 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h> 
#include <stdbool.h> 
int main(){ 
     int i, j, n; 
     char mark; 
     char marks[4]={'S', 'H', 'C', 'D'}; 
     int num; 
     bool cards[4][13]={false}; 
 
 
     scanf("%d ", &n); 
     for(i=0;i<n;i++){ 
         scanf("%c %d ", &mark, &num); 
         for(j=0;j<4;j++){ 
             if(mark==marks[j]){ 
                cards[j][num-1]=true; 
                 break; 
             } 
         } 
     } 
     for(i=0;i<4;i++){ 
         for(j=0;j<13;j++){ 
             if(!cards[i][j]){ 
                 printf("%c %d\n", marks[i], j+1); 
             } 
         } 
     }      return 0; 
 } 



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

int N, A, B, C;
vector<int> l;

const int INF = 1e9;

int solve(int i, int a, int b, int c) {
  if(i == N) {
    return min(a, min(b, c)) == 0 ? INF : abs(A-a) + abs(B-b) + abs(C-c) - 30;
  }

  int ans = INF;
  ans = min(ans, solve(i+1, a, b, c));
  ans = min(ans, solve(i+1, a + l[i], b, c) + 10);
  ans = min(ans, solve(i+1, a, b + l[i], c) + 10);
  ans = min(ans, solve(i+1, a, b, c + l[i]) + 10);
  return ans;
}

int main () {
  cin >> N >> A >> B >> C;
  l = vector<int>(N);
  rep(i,N) cin >> l[i];

  cout << solve(0, 0, 0, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#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() {
    ll a;
    double b;
    cin >> a >> b;
    b *= 100;
    ll ib = b+0.5;
    ll ans = a*ib;
    ans /= 100;
    cout << ans << endl;
    return 0;
}

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

int main() {
	// your code goes here
	string s, t;
	cin >> s;
	cin >> t;
	
	int ans;
	for(int i=0; i<3; i++)
	{
		if(s[i] == t[i])
		{
			ans += 1;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;

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

		String s = sc.next();

		TreeSet<String> sub = new TreeSet<String>();

		for(int i = 1; i <= 5; i++) {
			for(int n = 0; n < s.length(); n++) {
				if((n + i) >= s.length())
					sub.add(s.substring(n, s.length()));
				else
					sub.add(s.substring(n, (n + i)));
			}
		}
		/*
		for (String st: sub)
			System.out.println(st);
		*/

		int k = sc.nextInt();
		int count = 0;
		for(String st: sub) {
			count++;
			if(count == k) {
				System.out.println(st);
				break;
			}
		}
	}
}

Measured memory_bytes: 25436
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
string = input()
q = int(input())
for i in range(q):
  order = list(input().split())
  a, b = int(order[1]), int(order[2])
  if order[0] == "print":
    print(string[a:b+1])
  elif order[0] == "reverse":
    string = string[:a] + (string[a:b+1])[::-1] + string[b+1:]
  else:  
    string = string[:a] + order[3] + string[b+1:]


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N,K;
	cin>>N>>K;
	
	cout<<(N-1+K-2)/(K-1)<<endl;
	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
     String line=sc.next();
     StringBuffer s= new StringBuffer(line);
     int n=sc.nextInt();
     for(int i=0; i<n; i++){
    	 String ord=sc.next();
    	 if(ord.equals("print")){
    		 int a=sc.nextInt();
    		 int b=sc.nextInt();
    		 System.out.println(line.substring(a, b+1));
    	 }else if(ord.equals("reverse")){
    		 int a=sc.nextInt();
    		 int b=sc.nextInt();
    		 StringBuffer temp=new StringBuffer(s.substring(a, b+1));
    		 temp.reverse();
    		 s.delete(a, b+1);
    		 s.insert(a, temp);
    		 line=s.toString();


    	 }else if(ord.equals("replace")){
    		 int a=sc.nextInt();
    		 int b=sc.nextInt();
    		 String temp=sc.next();
    		 s.replace(a, b+1, temp);
    		 line=s.toString();


    	 }
     }

    }
}


Measured memory_bytes: 29240
package main
import (
  "fmt"
  "strconv"
  "strings"
)
func main() {
  var n,flag int64
  var m,l,k int
  var s,t string
  fmt.Scan(&n)
  flag = -1
  if n < 0 {
    n = -n
    flag = n%2
    n += flag
    n /= 2
  }
  s = strconv.FormatInt(n,4)
  s = reverse(s)
  m = len(s)
  l = 4*m
  var d []int = make([]int,l)
  for i:=0;i<m;i++ {
    switch s[i:i+1] {
      case "0":
      case "1":
        d[k]++
      case "2":
        d[k+1]++
        d[k+2]++
      case "3":
        d[k]++
        d[k+1]++
        d[k+2]++
    }
    k += 2
  }
  for i:=0;i<l;i++ {
    if d[i] > 1 {
      d[i] -= 2
      if i%2 == 0 {
        d[i+1]++
        d[i+2]++
      } else {
        d[i+1]--
      }
    }
  }
  k = -1
  for i:=l-1;i>=0;i-- {
    if d[i] != 0 {
      k = i
      break
    }
  }
  t = ""
  for i:=k;i>=0;i-- {
    t += strconv.Itoa(d[i])
  }
  if k < 0 { t = "0" }
  if flag >= 0 {
    t += strconv.FormatInt(flag,2)
  }
  fmt.Println(t)
}
func reverse(s string) string {
  var n int = len(s)
  var t []string = make([]string,n)
  for i:=0;i<n;i++ {
    t[i] = s[n-1-i:n-i]
  }
  return strings.Join(t,"")
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum = 700;
    for (int i = 0; i < 3; i++)
    {
        char a;
        cin >> a;
        if(a=='o')
            sum += 100;
    }
    cout << sum << endl;
    return 0;
}

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

int func(int x){
  if(x%100!=0) return 0;
  return func(x/100)+1;
}

int main(){
  int D,N;
  cin >> D >> N;
  int ans=0;
  for(int i=1;;i++){
    if(func(i)==D){
      ans++;
      if(ans==N){
        cout << i << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int t, d, l;
    while(cin >> t >> d >> l,t){
        int last = -2*d;
        int ans = 0;
        for(int i = 0; i < t-1; i++){
            int x;
            cin >> x;
            if(x >= l) last = i;
            if(last + d  > i) ans++;
        }
        int x;
        cin >> x;
        cout << ans << endl;
    }
}



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

int main() {
  int n;
  cin >> n;
  vector<float> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  float ans = v[0];
  for (int i = 1; i < n; i++)
  {
    ans = (ans + v[i])/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

numE_R = S.count('E')
numW_R = N - numE_R
numE_L, numW_L = 0, 0

ans = float('inf')
for Si in S:
    if Si == 'E':
        numE_R -= 1
    else:
        numW_R -= 1

    ans = min(ans, numW_L + numE_R)

    if Si == 'E':
        numE_L += 1
    else:
        numW_L += 1

print(ans)


Measured memory_bytes: 3672
#include <iostream>

using namespace std;

#define MAX 55
#define MINF -(1e8)

int N,M,a[MAX],b[MAX],c[MAX];
int memo[MAX][MAX][MAX];

int solve(int n,int l1,int m){
    if(n == N) return 0;
    int &res = memo[n][l1][m];
    if(res != MINF) return res;
    for(int i = 0 ; i <= min(8,m) ; i++){
        for(int j = 0 ; j <= i ; j++){
            for(int k = 0 ; k <= min(l1,8-j) ; k++){
                if(j + k == 0){
                    res = max(res,solve(n+1,i,m-i)+c[n]);    
                }else{
                    res = max(res,solve(n+1,i,m-i)+a[n]*j+b[n]*k);
                }
            }
        }
    }
    return res;
}

int main(){
    cin >> N >> M;
    for(int i = 0 ; i < N ; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    fill(&memo[0][0][0],&memo[MAX-1][MAX-1][MAX-1],MINF);
    cout << solve(0,0,M) << endl;
    return 0;
}

Measured memory_bytes: 1812
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut ab = Vec::new();
    for _ in 0..n {
        let (a, b) = {
            let i = read::<usize>();
            (i[0], i[1])
        };
        ab.push((a, b));
    }

    ab.sort_by_key(|x| x.0);
    ab.reverse();
    let mut count: usize = 0;
    let mut price: usize = 0;
    loop {
        let x = ab.pop().unwrap();
        if count + x.1 >= m {
            println!("{}", price + (m - count) * x.0);
            return;
        }
        count += x.1;
        price += x.1 * x.0;
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 6396
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    string s;
    cin >> s;
    int c = s.size() - 2;
    cout << s[0] << c << s[s.size() - 1] << endl;


    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
P=list(map(int,input().split()))
P=[i-1 for i in P]
par=[i for i in range(N)]
size=[1 for i in range(N)]
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return
for i in range(M):
  x,y=map(int,input().split())
  union(x-1,y-1)
count=0
for i in range(N):
  if find(i)==find(P[i]):
    count+=1
print(count)

Measured memory_bytes: 92468
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <19/May/2019 05:51:38 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


def main():
    #from math import log2
    n, k = get_ints()
    ans = 0
    for i in range(1, n + 1):
        curr = (1 / n)
        x = i
        while x < k:
            x *= 2
            curr *= (1 / 2)
        ans += curr
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 39280
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
{
	int n,i,f=0;
	string s;
	cin>>s;
	n=s.length();
	for(i=0;i<n;i++)
		{
			if(i%2==0&&s[i]!='U'&&s[i]!='D')
			{
				if(s[i]!='R')
					{
						f=1;
						break;
					}
			}
				
			else if(i%2!=0&&s[i]!='U'&&s[i]!='D')
				{
					if(s[i]!='L')
						{
							f=1;
							break;
						}
					}	
				
		}
	if(f==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
using namespace std;  
int n,m;
vector<int> vec(10);
const int INF = 1<<28;
int ans = INF;
string ans_s = "";
void res(int index,string sum,int rest){
  if(rest < 0)return;
  
  if(index == n && ans > stoi(sum)){
    ans = stoi(sum);
    ans_s = sum;    
    return;
  }
  if(index == n)return;
  for(int i = 0;i < 10;i++){
    res(index+1,sum+(char)(i+'0'),rest-vec[i]);
  }
  
}
int main(){

  cin >>  n >> m;
  
  for(int i = 0;i < 10;i++)cin >> vec[i];
  res(0,"",m);
  if(ans == INF){
    cout << "NA" << endl;
    return 0;
  }
  cout << ans_s << endl;

  
  return 0;
}


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

int main() {
    ll N, Q, all=0;
    cin >> N;
    vector<ll> A(N);
    for (ll i=0; i<N; i++) {
        cin >> A[i];
        all += A[i];
    }
    cin >> Q;
    vector<ll> B(Q), C(Q), S(Q);
    for (ll i=0; i<Q; i++) {
        cin >> B[i] >> C[i];
    }

    sort(A.begin(),A.end());
    ll maxA = A[N-1];
    vector<ll> count(pow(10,5),0);
    for (ll i=0; i<N; i++) {
        count[A[i]-1]++;
    }

    for (ll i=0; i<Q; i++) {
        all += count[B[i]-1] * (C[i]-B[i]);
        S[i] = all;
        count[C[i]-1] += count[B[i]-1];
        count[B[i]-1] = 0; 
    }

    for (ll i=0; i<Q; i++) {
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 6992
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N, C = inpl()

x, v = np.array([inpl() for _ in range(N)]).T

cwo = np.cumsum(v)-x
cwr = np.hstack(([0], cwo-x))
cwo = np.hstack(([0], cwo))
for i in range(N):
    cwr[i+1] = max(cwr[i], cwr[i+1])
av = v[::-1]
ax = C - x[::-1]

acwo = np.cumsum(av)-ax
acwr = np.hstack(([0], acwo-ax))
acwo = np.hstack(([0], acwo))
for i in range(N):
    acwr[i+1] = max(acwr[i], acwr[i+1])

ans1 = cwo + acwr[::-1]
ans2 = acwo + cwr[::-1]
print(max(np.max(ans1), np.max(ans2), 0))

Measured memory_bytes: 31608
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int N, M, C;
  cin >> N >> M >> C;
  
  vector<int> B(M,0);
  for (int i=0; i<M; i++) {
    cin >> B[i];
  }
  
  int ans=0, sum, a;
  for (int i=0; i<N; i++) {
    sum = C;
    for (int j=0; j<M; j++) {
      cin >> a;
      sum += B[j]*a;
    }
    if(sum>0)
      ans ++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    string s; cin >> s;
    int n = s.length();
    map<int, ll> m;
    ++m[0];
    ll ans = 0;
    int cur = 0, t = 1;
    rFOR(i, 0, n) {
        cur = (cur + (s[i] - '0') * t) % 2019;
        ans += m[cur];
        ++m[cur];
        t = t * 10 % 2019;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 3708
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var s = cin.Read;

            string[] d = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
            int[] day = { 7, 6, 5, 4, 3, 2, 1 };

            for (int i = 0; i < d.Length; i++)
            {
                if (d[i] == s)
                {
                    WriteLine(day[i]);
                }
            }
        }
    }

    public static class Extensions
    {
        
    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>]
#include <map>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;

int main(){
char x,y;cin>>x>>y;
if(x<y)cout<<'<';
else if(x>y)cout<<'>';
else cout<<'=';

}

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

import sys
input = sys.stdin.readline

def io_generator():
	return input()

def iil(a_io):
	return map(int, a_io().split())


#+++++++++++++++++++


def main(io):
	rr,n =iil(io)
	lmax=-1
	rmin=rr+1
	for i in range(n):
		l,r=iil(io)
		lmax=max(lmax,l)
		rmin=min(rmin,r)
	
	return max(0, rmin-lmax+1)

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	ret = main(io)
	if ret is not None:
		print(ret)

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

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

    int sum;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum += takoyaki[i] * takoyaki[j];
        }
    }

    printf("%d\n", sum);
}

Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 18.01.2020 02:59:16
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL
    freopen("C_vacation.in", "rt", stdin);
  #endif
  int n;
  cin >> n;
  vector <vector <int>> old_dp(3, vector <int>(2));
  for (int d = 0; d < n; d++) {
    vector <vector <int>> new_dp(3, vector <int>(2, 0));
    vector <int> arr(3);
    for (int i = 0; i < 3; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (i != j) {
          int gain = max(old_dp[j][0], old_dp[j][1]);
          new_dp[i][1] = max(new_dp[i][1], gain + arr[i]);
          new_dp[i][0] = max(new_dp[i][0], gain);
        } else {
          new_dp[i][1] = max(new_dp[i][1], old_dp[j][0] + arr[i]);
          new_dp[i][0] = max(new_dp[i][0], max(old_dp[j][1], old_dp[j][0]));
        } 
      }
    }
    old_dp = new_dp;
  }
 
  int a = max(old_dp[0][0], old_dp[0][1]);
  int b = max(old_dp[1][0], old_dp[1][1]);
  int c = max(old_dp[2][0], old_dp[2][1]);

  cout << max(a, max(b, c)) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int long long

int digit(int x){
    int c=0;
    while(x){
        x/=10;
        c++;
    }
    return c;
}

signed main(){
    int n;
    cin>>n;
    int m=sqrt(n)+1;
    int ans=MOD;
   for(int i=1;i<m;i++){
       int value=MOD;
       if(n%i==0){
           value=max(digit(i),digit(n/i));
       }
       ans=min(ans,value);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double ans,res;
int n,i,j,x[100010],y[100010],a[100010];
double f[10][10];
bool book[11];
inline void dfs(int step)
{
  if(step==n+1)
  {
    res=0;
    for(int i=1; i<n; i++)
      res+=f[a[i]][a[i+1]];
    ans+=res;
  }
  for(int i=1; i<=n; i++)
    if(book[i]==0)
    {
      book[i]=1;
      a[step]=i;
      dfs(step+1);
      book[i]=0;
    }
}
inline int fac(int x)
{
  int res=1;
  for(int i=2; i<=x; i++)res*=i;
  return res;
}
int main()
{
  cin>>n;
  for(i=1; i<=n; i++)
    cin>>x[i]>>y[i];
  for(i=1; i<=n; i++)
    for(j=1; j<=n; j++)
      if(i!=j)f[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
  dfs(1);
  ans/=fac(n);
  cout<<setprecision(10);
  cout<<ans;
  //printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
using namespace std;

static const int MAX_N = 100010;

int main(void){
  long long int N, X;
  long long int pos[MAX_N];
  cin >> N >> X;
  for(int i = 0; i < N; i++){
    cin >> pos[i];
  }
  pos[N] = X;

  long long int D = 0, min_dx = 9999999999;
  sort(pos, pos + N + 1);
  //まず隣同士で調べて，値の差の最小値を求める。そこまでmodを調べれば良い。
  for(int i = 0; i < N; i++){
    if(abs(pos[i] - pos[i + 1]) < min_dx) min_dx = abs(pos[i] - pos[i + 1]);
  }
  //min_dxまでmodが全て一致するかを調べる。
  //もし一致して，なおかつDが更新できる場合は更新する。
  long long int pos_mod[MAX_N];
  for(int i = min_dx; i >= 1; i--){
    for(int j = 0; j < N + 1; j++){
      pos_mod[j] = pos[j] % i;
    }
    sort(pos_mod, pos_mod + N + 1);
    if(pos_mod[0] == pos_mod[N]){
      D = i;
      break;
    }
  }
  cout << D << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int , int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti set <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    string s,t;
    cin>>s>>t;
    ll n=s.length(),m=t.length();
    ll a[n+1][m+1];
    s=" "+s;
    t=" "+t;
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            a[i][j]=0;
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(s[i]==t[j])
                a[i][j]=a[i-1][j-1]+1;
            else
                a[i][j]=max(a[i-1][j],a[i][j-1]);
        }
    }
    string ans="";
    while((n>0)&&(m>0))
    {
        if(s[n]==t[m])
        {
		    ans=s[n]+ans;
		    n--;
		    m--;
		}
        else if(a[n-1][m]>a[n][m-1])
            n--;
        else
            m--;
    }
    cout<<ans;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

    
ll a,b,c,n,m,k,t=1;

void solve()
{ 
  cin>>n;
  n--;
  cout<<n*(n+1LL)/2LL;
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int sum5 = 0;
	int sum7 = 0;
	if(a == 7) sum7++;
	if(a == 5) sum5++;
	if(b == 7) sum7++;
	if(b == 5) sum5++;
	if(c == 7) sum7++;
	if(c == 5) sum5++;
	if(sum7 == 1 && sum5 == 2) printf("YES\n");
	else printf("NO\n");
	}

Measured memory_bytes: 128
// Problem: B - Substring
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

//=========================================================

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//=========================================================
#ifdef DEBUG
#define xtp xtp1
#else
#define xtp(x)
#endif
//=========================================================

#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define F first
#define S second
#define pb push_back
#define endl "\n"

#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define rSORT(a) sort(rALL(a))
#define REV(a) reverse(ALL(a))
#define sqr(x) ((x) * (x))

#define TEZ                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);

const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;

signed main() {
	TEZ;

	string s, t;

	cin >> s >> t;

	int jv = INF;

	for (int i = 0; i <= (int)s.size() - t.size(); i++) {
		int jj = 0;
		for (int j = 0; j < (int)t.size(); j++) {
			jj += s[i + j] != t[j];
		}

		jv = min(jj, jv);
	}

	cout << jv << endl;

	return 0;
}


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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            Console.ReadLine();
            var input = Console.ReadLine().Split().Select(p => long.Parse(p));
            Console.WriteLine("{0} {1} {2}", input.Min(), input.Max(), input.Sum());
        }
    }
}

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

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

  ll sum = 0;
  rep(i, n-1) sum += abs(a[i+1] - a[i]);
  sum += abs(a[0]);
  sum += abs(a[n-1]);
  rep(i, n) {
    ll ans = sum;
    if (i == 0) {
      ans -= abs(a[0]);
      ans -= abs(a[0]-a[1]);
      ans += abs(a[1]);
    }
    else if (i == n-1) {
      ans -= abs(a[n-1]);
      ans -= abs(a[n-1] - a[n-2]);
      ans += abs(a[n-2]);
    }
    else {
      ans -= abs(a[i+1]-a[i]);
      ans -= abs(a[i-1]-a[i]);
      ans += abs(a[i+1]-a[i-1]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1664
n, d = gets.split.map(&:to_i)
p = []
n.times do
  p << gets.split.map(&:to_i)
end
cnt = 0
(0...n).to_a.combination(2).each do |c|
  p1 = p[c[0]]
  p2 = p[c[1]]
  tmp = 0
  d.times do |i|
    tmp += (p1[i] - p2[i]) ** 2
  end
  dist = Math.sqrt(tmp)
  cnt += 1 if dist == dist.ceil
end
puts cnt


Measured memory_bytes: 14296
using System;

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c,s,m;
            string[] word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            m = a;
            if (m < b) m = b;
            if (m < c) m = c;
            s = a + b + c - m;

            Console.WriteLine(s);
            //Console.ReadKey();
        }
    }
}

Measured memory_bytes: 27468
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<cmath>
#define int long long int
int32_t main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 int arr1[7]={1,3,5,7,8,10,12};
	 int arr2[4]={4,6,9,11};
	 int arr3[1]={2};
	 int x,y;
	 cin>>x>>y;
	 bool result=false;
	 int count=0;
	 int i;
	 for(i=0;i<7;i++)
	 {
		 if(arr1[i]==x||arr1[i]==y)
		   count++;
	 }
	 if(count==2)
	 {
		 result=true;
	 }
	 count=0;
	 for(i=0;i<4;i++)
	 {
		 if(arr2[i]==x||arr2[i]==y)
		   count++;
	 }
	 if(count==2)
	 {
		 result=true;
	 }
	 if(result)
	 {
		 cout<<"Yes"<<endl;
	 }
	 else  
	   cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    
    int a, b, c;
    int cnt = 0;
    cin >> a >> b >> c;
    
    for(int i = a; i <= b; ++i)
    {
        if( c % i == 0)
         ++cnt;
    }
    
    cout << cnt << endl;
    
    return 0;
}


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

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

    vector<int> v;
    rep(i,n)
    {
        int a;
        cin >>a;
        if(v.size()==0) v.pb(a);
        else
        {
            if(v[v.size()-1]!=a) v.pb(a);
        }
    }

    n = v.size();
    if(n==1) return 1;

    vector<long long> d(n-1);
    rep(i,n-1) d[i] = v[i+1]-v[i];

    // rep(i,n-1) printf(" d[ %d] %d\n", i,d[i]);

    int ans = 1;
    int st = 0;
    while(st<n-1)
    {
        // printf(" st %d\n", st);

        int idx = st;
        while(idx<n-1 && d[st]*d[idx]>0) ++idx;

        int diff = idx-st;
        // printf(" %d\n", diff);
        ans = max(ans,diff+1);
        st = idx;
    }

    return ans;
}

int main()
{
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 4148
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
sum = 0
count = 0
for j in range(N-1):
    for k in range(j+1, N):
        for x in range(D):
            sum += (X[j][x] - X[k][x])**2
        if (sum**0.5).is_integer():
            count += 1
        sum = 0
print(count)


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

using namespace std;

char s[200005], t[200005];
int ans;

int main() {
    scanf("%s %s", s, t);
    for (int i = 0; i < strlen(s); i++) {
        if (s[i] != t[i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4108
//package ABC170;

import java.util.Scanner;
import java.util.*;
import java.io.*;
import java.lang.*;



class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		
		for(int i=0;i<5;i++)
		{
			int a=sc.nextInt();
			if(a==0)
			{
				System.out.println(i+1);
				break;
			}
		}
		

	}

}


Measured memory_bytes: 35700
#include<stdio.h>
int mx(int a,int b){
  if(a<b)return b;
  else   return a;
}
int main(){
  int N,W,c=1,mi,max,i,j;
  int k[1001],w[1001];
  while(1){
    scanf("%d",&W);
    if(!W)break;
    scanf("%d",&N);
    int dp[1001][1001]={0};
    for(i=0;i<N;i++){
      scanf("%d,%d",&k[i],&w[i]);
    }
    for(i=N-1;i>=0;i--){
      for(j=0;j<=W;j++){
	if(j<w[i])dp[i][j]=dp[i+1][j];
	else{
	  dp[i][j]=mx(dp[i+1][j],dp[i+1][j-w[i]]+k[i]);
	}
      }
    }
    max=0;
    mi=0;
    for(i=0;i<=W;i++){
      if(max<dp[0][i]){
	max=dp[0][i];
	mi=i;
      }
    }
    printf("Case %d:\n%d\n%d\n",c++,max,mi);
  }
  return 0;
}

Measured memory_bytes: 4528